# problem excluding group from task in playbook

**URL:** <https://forum.ansible.com/t/problem-excluding-group-from-task-in-playbook/14018>\
**Category:** Ansible Project\
**Created:** [November 27, 2013, 9:18pm UTC](https://forum.ansible.com/t/problem-excluding-group-from-task-in-playbook/14018 "2013-11-27T21:18:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![oliver\_bril](https://avatars.discourse-cdn.com/v4/letter/o/f9ae1b/32.png) [@oliver\_bril](https://forum.ansible.com/u/oliver_bril)\
**Post date:** [November 27, 2013, 9:18pm UTC](https://forum.ansible.com/t/problem-excluding-group-from-task-in-playbook/14018/1 "2013-11-27T21:18:57Z")

</div>

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:

---

<div class="post-metadata">

**Author:** ![Serge\_van\_Ginderacht](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Serge\_van\_Ginderacht](https://forum.ansible.com/u/Serge_van_Ginderacht)\
**Post date:** [November 27, 2013, 9:34pm UTC](https://forum.ansible.com/t/problem-excluding-group-from-task-in-playbook/14018/2 "2013-11-27T21:34:07Z")

</div>

​add this conditional to the task where it should not run:​

&nbsp;&nbsp;&nbsp;​when: inventory\_hostname not in groups.ntpservers​

Serge

---

<div class="post-metadata">

**Author:** ![oliver\_bril](https://avatars.discourse-cdn.com/v4/letter/o/f9ae1b/32.png) [@oliver\_bril](https://forum.ansible.com/u/oliver_bril)\
**Post date:** [November 28, 2013, 10:23am UTC](https://forum.ansible.com/t/problem-excluding-group-from-task-in-playbook/14018/3 "2013-11-28T10:23:11Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Serge\_van\_Ginderacht](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Serge\_van\_Ginderacht](https://forum.ansible.com/u/Serge_van_Ginderacht)\
**Post date:** [November 28, 2013, 10:32am UTC](https://forum.ansible.com/t/problem-excluding-group-from-task-in-playbook/14018/4 "2013-11-28T10:32:32Z")

</div>

​the groups magic variable ​is mentioned here:  
[http://www.ansibleworks.com/docs/playbooks\_variables.html#magic-variables-and-how-to-access-information-about-other-hosts](http://www.ansibleworks.com/docs/playbooks_variables.html#magic-variables-and-how-to-access-information-about-other-hosts)

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [November 28, 2013, 8:32pm UTC](https://forum.ansible.com/t/problem-excluding-group-from-task-in-playbook/14018/5 "2013-11-28T20:32:13Z")

</div>

Often easier to just start a new play;

- hosts: group1:!group2

Targets all hosts in group1 that are not in group2

---

<div class="post-metadata">

**Author:** ![oliver\_bril](https://avatars.discourse-cdn.com/v4/letter/o/f9ae1b/32.png) [@oliver\_bril](https://forum.ansible.com/u/oliver_bril)\
**Post date:** [November 28, 2013, 8:56pm UTC](https://forum.ansible.com/t/problem-excluding-group-from-task-in-playbook/14018/6 "2013-11-28T20:56:19Z")

</div>

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
