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": ""}
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/0dbcbeda-ba8f-4fa7-9a31-542e0d5030d4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.