Skip to content

Instantly share code, notes, and snippets.

@bryanwb
Last active September 3, 2015 13:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bryanwb/309a4f9a26fc4ed94e92 to your computer and use it in GitHub Desktop.
Save bryanwb/309a4f9a26fc4ed94e92 to your computer and use it in GitHub Desktop.
modifying a dictionary in a loop
# this fails on the "set" tag
- set_fact: instances="{%- set instances = dict() %}
{%- for group in group_names %}
{%- for host in groups[group] %}
{%- if hostvars[host].get('InstanceId', None) %}
{%- if hostvars[host].get('Platform', None) == 'windows' %}
{%- set tmp = instances.setdefault(host, hostvars[host]['InstanceId']) %}
{%- endif %}
{%- endif %}
{%- endfor %}
{%- endfor %}{{instances}}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment