Dear all,
I’m trying probably something very simple but can’t get it to work. I’m trying to exclude a group from a task. I have a playbook for all hosts (hosts: all) but in one particular task I want to exclude a group, how do I do that?
I know I can do something like:
hosts: all:!ntpservers
but that also excludes the ntpserver from all the other tasks.
This is what I’m trying to do:
I’m installing an ntp daemon on all systems but want to install the configuration ntpd.conf on all systems EXCEPT for the servers in the group “ntpservers”. I want to install a different configuration file on those servers because these will become the real ntp servers, the others will become clients.
I have this so far:
add this conditional to the task where it should not run:
when: inventory_hostname not in groups.ntpservers
Serge
Serge,
Thanx a lot, working like a charme.
Perhaps a stupid question for a newbie like me but where can i find all these kind of parameters?
I never ask a question before googling and trying but in this case i spent 2 days searching and couldn’t find anything (which also could mean i searched for the wrong keywords )
Kind regards,
Oliver.
Often easier to just start a new play;
Targets all hosts in group1 that are not in group2
Michael,
I believe you are right it’s much easier to start a new play and that was also the first solution i found. Because I’m just a newbie to ansible i tried to keep things consistent and place everything which is default on a server (host file, resolve.conf , ntp.conf etc) into a playbook “common” and the applications in their own playbook. Problem was that i wanted to run both a ntp server as a ntp client. Right now everything works perfectly but i will consider your approach when i go along and everything start to become too complicated.
By the way, till now i really like ansible.
Thanks,
Kind regards.
Oiver