Build the Next-Generation Data Center
6 week online course starting in spring 2017

Navigating Complex Data Structures in Ansible Playbooks

Have you ever tried to navigate complex data structures within Ansible playbooks using awkward looping constructs and convoluted map filters?

It might be easier to munge the data structure into a more appropriate format first and then use the munged data in subsequent tasks. Wondering how to do it? Here’s a short step-by-step guide.

Next Steps

If this trick was all you were looking for I hope you’ll find it useful. If you’re looking for a bigger picture, start with Ansible for Networking Engineers webinar, explore other network automation webinars and register for the Building Network Automation Solutions online course.

1 comment:

  1. Great article
    You said: "writing a Python module (Jinja2 filter or Ansible plugin) that transforms data is often easier than using a Jinja2 template"
    Absolutely agreed to that.


    And there is one more way to transform any input data to a data structure that ansible could loop over.
    Instead of running playbooks with a text-based inventory file (-i ./hosts) you can run it with something executable (-i acl2ansible_json.py)
    They call it dynamic inventory feature:
    http://docs.ansible.com/ansible/dev_guide/developing_inventory.html

    But this feature can broke a text based model driven paradigm off to something else ��

    ReplyDelete

You don't have to log in to post a comment, but please do provide your real name/URL. Anonymous comments might get deleted.