DEV Community

loading...

Jamespath in Ansible Playbooks

Santhosh Balasa
Passionate Senior Full Stack Developer around 10+ yrs of IT experience.
Updated on ・1 min read

Have you ever heard of JSON query language ? Well, if not take a look at this: https://jmespath.org/examples.html

This is absolutely brilliant when you're trying to get the exact information from the JSON results spitted by Ansible play runs especially, let me show you an example on how you can actually register the output to a variable and run your query on it.

Example:

  - name: Sample Playbook
    // Fill up your task
    no_log: True
    register: example_output

  - name: Json Query
    set_fact:
      query_result:
        example_output:"{{ example_output | json_query('results[*].name') }}" 
Enter fullscreen mode Exit fullscreen mode

Discussion (0)