Skip to content

Instantly share code, notes, and snippets.

@mrlesmithjr
Created April 6, 2018 02:32
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 mrlesmithjr/3c149124f2894c572939bf41c6bc5ad5 to your computer and use it in GitHub Desktop.
Save mrlesmithjr/3c149124f2894c572939bf41c6bc5ad5 to your computer and use it in GitHub Desktop.
{{ ansible_managed|comment }}
{% set _groups = [] %}
{% for vm in vms %}
{% if vm['groups'] is defined %}
{% for _group in vm['groups'] %}
{% set _ = _groups.append(_group) %}
{% endfor %}
{% endif %}
{% endfor %}
{% set _groups = _groups|unique|sort|list %}
{% for _group in _groups %}
[{{ _group }}]
{% for vm in vms %}
{% if vm['groups'] is defined and vm['state'] == "present" %}
{% for __group in vm['groups'] %}
{% if __group == _group %}
{% for host in groups['provisioned_vms'] %}
{% if host == vm['name'] %}
{{ host }} ansible_host={{ hostvars[host]['ansible_host'] }} mac_address={{ hostvars[host]['mac_address'] }} uuid={{ hostvars[host]['uuid'] }}
{% endif %}
{% endfor %}
{% endif %}
{% endfor %}
{% endif %}
{% endfor %}
{% endfor %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment