Hi all,
I have a group named cluster in my inventory file, which has 2 nodes, swarm1 & swarm2.
and the following playbook, trying to use map('extract') to get the IP address of the other node. I can print out the ip just fine by accessing the hostvars directly, but not when i use map. what's wrong?
---
- hosts: cluster
tasks:
- debug: msg={{ hostvars[inventory_hostname].ansible_default_ipv4.address }}
- debug: msg={{ groups['cluster'] | difference([inventory_hostname]) }}
- debug: msg={{ hostvars['swarm1']['ansible_default_ipv4']['address'] }}
- debug: msg={{ hostvars['swarm2']['ansible_default_ipv4']['address'] }}
- debug: msg={{ groups['cluster'] | difference([inventory_hostname]) | map('extract', hostvars, ['ansible_default_ipv4', 'address'] ) | list }}
which got an error in the last task
TASK [debug] *******************************************************************
ok: [swarm1] => {
"msg": "10.10.35.224"
}
ok: [swarm2] => {
"msg": "10.10.35.226"
}
TASK [debug] *******************************************************************
ok: [swarm1] => {
"msg": [
"swarm2"
]
}
ok: [swarm2] => {
"msg": [
"swarm1"
]
}
TASK [debug] *******************************************************************
ok: [swarm1] => {
"msg": "10.10.35.224"
}
ok: [swarm2] => {
"msg": "10.10.35.224"
}
TASK [debug] *******************************************************************
ok: [swarm1] => {
"msg": "10.10.35.226"
}
ok: [swarm2] => {
"msg": "10.10.35.226"
}
TASK [debug] *******************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: TemplateRuntimeError: no filter named 'extract'
fatal: [swarm1]: FAILED! => {"failed": true, "msg": "Unexpected failure during module execution.", "stdout": ""}
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: TemplateRuntimeError: no filter named 'extract'
fatal: [swarm2]: FAILED! => {"failed": true, "msg": "Unexpected failure during module execution.", "stdout": ""}