Search code examples
jsonansiblejmespath

what does @ symbol do in this [@][] ansible code?


I would like to know what @ symbol does in this line of code and [@][] do? This is being used in Ansible. Thank you.

json_query("response.result.job  |  [@][]")

The whole code:

- name: task1
        <removed for simplicity>
        cmd: 'show jobs all'
      register: all_jobs
      until: |
        all_jobs is not failed
        and (all_jobs.stdout | from_json | json_query("response.result.job|[@][]") | default([], true) | length > 0)
        and (all_jobs.stdout | from_json | json_query("response.result.job|[@][]")
        | json_query("[?status != 'FIN']") | length == 0)
      retries: 60
      delay: 30

Solution

  • For those who are curious, I think I found the answer. It is all about jmespath. @ is the current node. [] will flat a list. [][] will flat nested lists. [@][] will flat second level list. To understand this please go to this link below. There are examples there.

    https://jmespath.org/tutorial.html