Skip to content

Instantly share code, notes, and snippets.

@rsvalerio
Created June 28, 2017 09:02
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 rsvalerio/8366c443ada0c42513a652899ed58577 to your computer and use it in GitHub Desktop.
Save rsvalerio/8366c443ada0c42513a652899ed58577 to your computer and use it in GitHub Desktop.
netbox-ansible-inventory
{% regroup queryset|dictsort:"device_role.id" by device_role as per_role %}
{% for role in per_role %}
[{{ role.grouper.slug }}]
{% for device in role.list %}{% if device.primary_ip %}
{{ device.name|slugify }} ansible_host={{ device.primary_ip.address.ip }}{% endif %}{% endfor %}
{% endfor %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment