Search code examples
ansibleansible-facts

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?


Solution

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