How do you change ansible_default_ipv4?

jd50 picture jd50 · Apr 7, 2015 · Viewed 20k times · Source

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?

Answer

Kashyap picture Kashyap · Apr 7, 2015

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