To illustrate what I mean, the API query result looks similar to this: " vars: query: '192.168.1.1 1 ')]. In the first example, I needed to iterate over a list of objects returned from an API query, find an object based on a supplied name, and return the ID of the object. Ansible jsonquery to filter list of dict with different key. Ansible playbook to get value from some dictionary keys. ![]() If this is new to you, there are plenty of JMESPath examples you can learn from in JMESPath examples. You can extract and transform elements from a JSON document. The filter is already well-documented, but I thought I would share a few examples of how it came in handy for me.Įxample 1 – Finding a specific value in a list of objects Ansible jsonquery - struggling with syntax. Use jsonquery filter (JMESPath) If you are familiar with a JSON query language such as JMESPath, then Ansible's jsonquery filter is your friend because it is built upon JMESPath, and you can use the same syntax. This is a tutorial of the JMESPath language. Multiple jsonquery in Ansible I have the following yaml file. Recently I stumbled across the Ansible json_query filter as a very neat solution to a problem that would have been otherwise messy to solve in Ansible. This is where the Jinja2 and Ansible filters can really shine. ![]() While Ansible is busy fighting its own internal battle not to become a fully fledged programming language, instead remaining as simple and purely declarative as possible, it is still often necessary to work with more complex data structures.
0 Comments
Leave a Reply. |