ansible: get network IP from a host

Viewed 1538

I am using ansible to set up a NFS server on linux machine. I would like to give access to to the /data_to_share directory present on NFS server to all machines sharing the same LAN. This is why I would like to export the NFS at:

/data_to_share      192.168.0.0/24(rw)   

With ansible I can get the IP address of the NFS host, using the variable:

{{ ansible_default_ipv4.address }}

That would return 192.168.0.13. Is there a variable for the network IP, i.e.192.168.0.0, or some other way to get there? thanks

1 Answers

I found the relevant build-in ansible variables that I needed running an ad-hoc action:

ansible -m setup hostname

Those are:

ansible_default_ipv4.network
ansible_default_ipv4.netmask

I can build the export path using

"{{ ansible_default_ipv4.network }}/{{ansible_default_ipv4.netmask}}"

that renders to: 192.168.0.0/255.255.255.0

Related