I want to copy one version of a file to a server if it has an interface in a specific subnet, or a different version if it does not have an interface in that subnet. Below is a working, but I think less than optimal solution. I'm hoping there is a better way that meets the following criteria...
- stays dynamic (use facts, I don't want to have to manually set variables for every server and manually create groups for servers in and not in the subnet)
- less repetitive (could it be handled in one task?)
- not have to list out every possible interface name (eg. eth0, eth1, ..., bond0, bond1, ... etc)
working version...
- name: copy file version 1 to server
copy:
src: files/myfile.vs1
dest: /etc/myfile
when: (ansible_eth0.network == "192.168.0.0") or
(ansible_eth1.network == "192.168.0.0") or
(ansible_eth2.network == "192.168.0.0")
...
- name: copy file version 2 to server
copy:
src: files/myfile.vs2
dest: /etc/myfile
when: (ansible_eth0.network != "192.168.0.0") and
(ansible_eth1.network != "192.168.0.0") and
(ansible_eth2.network != "192.168.0.0")
...