2

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
  • The question is valid for the site and properly formatted. Even more, this is more advanced usage an not an easy thing to look up if you're new to Ansible. Let's try not to be purposefully rude. – Colyn1337 Aug 12 '21 at 21:30
  • I took a look at JMESPATH syntax and it seems @ means the current node but still I don't understand what [@][] in this code. I appreciate the help. – user16635540 Aug 13 '21 at 13:46

1 Answers1

1

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