Vijesh
Vijesh

Reputation: 1208

Ansible setup module's filter is not working when use with playbook

I am trying to filter setup module for a specific fact, but no output when doing so with a playbook. It works well with adhoc command!

example playbook:

---
- name: facts test
  hosts: localhost
  connection: local
  gather_facts: false
  tasks:
  - ansible.builtin.setup:
      filter:
        - "ansible_all_ipv4_addresses"

  - debug: var=ansible_all_ipv4_addresses
...

Output:

TASK [debug var=ansible_all_ipv4_addresses] ****************************************************************
ok: [localhost] => {
    "ansible_all_ipv4_addresses": "VARIABLE IS NOT DEFINED!"
} 

Expected Output:

TASK [debug var=ansible_all_ipv4_addresses] ****************************************************************
ok: [localhost] => {
    "ansible_all_ipv4_addresses": [
        "192.168.1.1"
    ]
} 

Adhoc command ansible localhost -m setup -a "filter=ansible_all_ipv4_addresses" produces proper output.
Any idea what is wrong here?
Ansible Version I've tested:

$ ansible --version
ansible 2.9.6 

Thanks,

Upvotes: 1

Views: 1197

Answers (1)

toydarian
toydarian

Reputation: 4554

That is almost certainly a problem with your ansible version. The filter parameter takes a list since ansible-core version 2.11, you are probably using an older one.

You have two possibilities:

  • Change the filter to filter: "ansible_all_ipv4_addresses"
  • Update to the latest version of ansible

Upvotes: 1

Related Questions