I am for some reason, really struggling to pull an item from stdout and register it.
Inside play:
debug:
msg: “{{ output.stdout }}”
Output:
ok: [localhost] => {
“msg”: {
“code”: 200,
“data”: “10.50.3.26”,
“success”: true,
“time”: 0.006
}
}
What I am looking to do is extract the ‘data’ item from the result.
I have tried {{ output.stdout[data] }} amongst other things but I just don’t seem to be able to get it going and Googling doesn’t seem to show what I’m after. I can only with with_items elements.
If you have already registered the output you can use “set_facts” module to filter the ipaddress from the output and then use the ipaddress and use in playbook as you want. For e.g.:
hosts: localhost
tasks:
name: run Test task
register: output
debug:
msg: “{{ output[’data’] }}” # this will just output the IP address
name: get the data as ip
set_fact:
ip: “{{ output[‘data’] }}”
debug:
msg: “{{ ip }}” # this will stdout the ip but can also be used as variable in play as well