I discovered the other day that when a register variable is used in a loop, like this
`
- name: Generate pw’s for users
command: “/some_path/generate_hashed_pw.sh -u {{ item }}”
register: hashed_pws
with_items: - joe
- sally
- john
`
the hashed_pws register is a hash that contains a results key, which is an array of hashes, like so
{ "hashed_pws: { "changed" : true, "some_other_key" : "some_other_value", "results" : [ { "item" : "joe", "stdout": "joes_hashed_pw", "some_other_key" : "some_other_value" }, { "item" : "sally", "stdout": "sallys_hashed_pw", "some_other_key" : "some_other_value" }, { "item" : "john", "stdout": "johns_hashed_pw", "some_other_key" : "some_other_value" } ] } }
So what is the syntax to directly access, the “stdout” element in each of the hash elements in the array? In other words, I want:
`
- debug: msg=“Sallys hashed pw is {{ hashed_pws.results[SOME_KEY_TO_DIRECTLY_GET_SALLYS_STDOUT_VALUE] }}”
`
This is probably a python question as much as it is an Ansible question.