Your browser failed to load CSS style sheets. Your browser or web proxy might not support elliptic-curve TLS

Building network automation solutions

9 module online course

Start now!
back to overview

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.

Please read our Blog Commenting Policy before writing a comment.

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

Constructive courteous comments are most welcome. Anonymous trolling will be removed with prejudice.

Sidebar