Jamespath in Ansible Playbooks

sbalasa

Santhosh Balasa

Posted on June 22, 2020

Jamespath in Ansible Playbooks

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
💖 💪 🙅 🚩
sbalasa
Santhosh Balasa

Posted on June 22, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related