map extract not working?

313 views
Skip to first unread message

Arthur Tsang

unread,
Apr 26, 2016, 12:31:38 PM4/26/16
to Ansible Project
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": ""}

Johannes Kastl

unread,
May 3, 2016, 3:21:27 AM5/3/16
to ansible...@googlegroups.com
On 26.04.16 03:56 Arthur Tsang wrote:

> An exception occurred during task execution. To see the full traceback, use
> -vvv. The error was: TemplateRuntimeError: no filter named 'extract'

I would say your syntax is wrong. Apparently ansible does not know
your filter called extract.

Johannes

signature.asc
Reply all
Reply to author
Forward
0 new messages