FreeKB - ansible_default_ipv4.address variable
Ansible - ansible_default_ipv4.address variable

The gather_facts module must be set to true, which is the default setting of the gather_facts module. In other words, the gather_facts module must not be set to false.

The ansible_default_ipv4.address variable will return the default IPV4 address of your control node (that's your Ansible server). For example, let's say you have the following playbook.

---
- hosts: all
  tasks:
    - debug:
        msg: "{{ ansible_default_ipv4.address }}"

 

Running this playbook should return the IPv4 address of the control node.

TASK [debug]
ok: [server1.example.com] => {
    "msg: "10.1.2.3"
}

 

You could also use hostvars to return the distribution of the managed node (e.g. target system). For example, let's say you have the following playbook.

---
- hosts: all
  tasks:
    - debug:
        msg: "{{ hostvars[inventory_hostname].ansible_default_ipv4.address }}"

 

Running this playbook should return the IPv4 address of the managed node.

TASK [debug]
ok: [server1.example.com] => {
    "msg: "192.168.1.2"
}

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter 53ed3 in the box below so that we can be sure you are a human.




Comments

Web design by yours truely - me, myself, and I   |   jeremy.canfield@freekb.net   |