I'd like to change ansible_default_ipv4 to point to eth1 instead of eth0. Can I do this in either the playbook or via the --extra-vars option?
ansible_all_ipv4_addresses contains all server IP addresses except for localhost. This is example of facts for server with no default IPv4 address: ...
To access the variables from Ansible facts in the Ansible playbook, we need to use the actual name without using the ansible keyword. The gather_facts module from the Ansible playbook runs the setup module by default at the start of each playbook to gather the facts about remote hosts.
ansible uses command ip -4 route get 8.8.8.8
to get the default ipv4 interface. You can change your ip/routing tables to make eth1
the default route and it'll return it.
Or you can use a custom fact.
PS: using set_fact
to override the ansible_default_ipv4
fact, but it has it's own pitfalls due to caching, scope, ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With