Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you change ansible_default_ipv4?

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?

like image 374
jd50 Avatar asked Apr 07 '15 15:04

jd50


People also ask

What is ansible_all_ipv4_addresses?

ansible_all_ipv4_addresses contains all server IP addresses except for localhost. This is example of facts for server with no default IPv4 address: ...

How do you get Ansible facts?

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.


1 Answers

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, ...

like image 130
Kashyap Avatar answered Oct 04 '22 01:10

Kashyap