The task includes an option with an undefined variable. The error was: ansible_all_ipv4_addresses is undefined.

Why would I be getting this error, if I am connecting over ipv4? I'm trying to dump this like,

"{{ ansible_all_ipv4_addresses[0] }}"

And I can verify that it is valid,

$ ansible -u centos -m setup | grep ansible_all_ipv4_addresses -A2 -B1
    "ansible_facts": {
        "ansible_all_ipv4_addresses": [

But then very similar to the above,

$ ansible -u centos -m debug -a "msg='{{ansible_all_ipv4_addresses}}'" | FAILED! => {
    "msg": "The task includes an option with an undefined variable. The error was: 'ansible_all_ipv4_addresses' is undefined"
  • Have you tried using "{{ ansible_host }}"?
    – Panki
    Jan 10, 2020 at 8:25

2 Answers 2


For me the problem was that my playbook had

gather_facts: false

Set at the top of my playbook. As to why the use of facts does not work with the debug module, for that see this question


For me it was that Ubuntu in docker didn't have iproute2 package by default.

I see you are using CentOS, but it was the first link in Google, so i thought it's worth to mention this thread, where i actually found the answer.

Here is a block i added to my playbook, in case someone find it usful:

- name: Install iproute2 on ubuntu to gather facts properly
    - name: install iproute
        name: iproute2
        state: present
    - name: Recollect facts
          - all
    - debug: msg="{{ hostvars[inventory_hostname]['ansible_all_ipv4_addresses'] }}"
  when: ansible_distribution == "Ubuntu"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .