I'm toying with the idea of having a playbook that runs a certain task when a server is in a group and another task when it is not in a group.
Say I have office1 with all servers and I have a primary DHCP server:
[office1] server1 server2 server3 [dhcp] server2
I want to make sure that I only have one DHCP server:
- include: tasks/add-dhcp.yml when: inventory_hostname in dhcp - include: tasks/remove-dhcp.yml when: inventory_hostname not in dhcp
So that when I change DHCP to server3, it will be installed on 3 and removed from 2. The roll will then run on all office1 servers when a new DHCP deploy is done.
Any ideas with this? Is it a bad idea? How would you solve this problem?