Good afternoon.
I have this snippet of code, that sets a proxy variable if the default ipv4 IP address is in 10 net space. I had read somewhere that using the ansible_default_ipv4 fact, wasn’t always reliable. So is there a better way to grab the primary IP other than what I did below?
I hadn’t heard about any inconsistencies either, which is why I figured I’d ask here. I thought about the ipaddr filter, but you need to install a python module for it to work. (netaddr I think) and I was just trying to figure it out using the base set of modules, etc. Thanks for the info though, I appreciate it
Ok… so some more info… I think I have a workable solution. I"ll be testing it tomorrow, but I am 99% sure I have it figured out. The code above, actually didn’t work as I thought… so, I changed this:
to this:
when: hostvars[inventory_hostname][‘ansible_default_ipv4’][‘address’] | regex_search(‘^10.[0-9]+’)
That seems to have gotten me the result I was looking for.
As for the “default ipv4” not being consistent, I went back and re-read the article. Basically, the author said that if you don’t set a default route, then the default.ipv4.address will be empty. I decided this was not a huge deal, since I can’t think of a situation where I have installed a server without a default route.
So anyway, thanks again for the help, I do appreciate it.