problem excluding group from task in playbook

1,695 views
Skip to first unread message

oliver bril

unread,
Nov 27, 2013, 4:18:57 PM11/27/13
to ansible...@googlegroups.com

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:

  #-------------------------------------------------------------------#

  #                              NTP                                             #

  #-------------------------------------------------------------------#

  - name: Role:common - ensure ntpd is installed on all nodes

    yum: pkg=ntp state=installed

    tags: ntp

 

  - name: Role:common - be sure ntp is configured

    template: src=ntp.conf.j2 dest=/etc/ntp.conf

    notify:

      - Handlers:common - restart ntpd

    tags: ntp

 

  - name: Role:common - be sure ntpd is running and enabled

    service: name=ntpd state=running enabled=yes

    tags: ntp 


And I believe in the template part I have to exclude the group “ntpservers” so I can install a different configuration file via a separate playbook especially for the ntpservers (via roles).

Hope someone can help me out. 

Kind regards,

Oliver.

 

Serge van Ginderachter

unread,
Nov 27, 2013, 4:34:07 PM11/27/13
to ansible...@googlegroups.com

On 27 November 2013 22:18, oliver bril <olive...@gmail.com> wrote:
EXCEPT for the servers in the group “ntpservers”.

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

   ​when: inventory_hostname not in groups.ntpservers​


Serge

oliver bril

unread,
Nov 28, 2013, 5:23:11 AM11/28/13
to ansible...@googlegroups.com
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.

Serge van Ginderachter

unread,
Nov 28, 2013, 5:32:32 AM11/28/13
to ansible...@googlegroups.com

On 28 November 2013 11:23, oliver bril <olive...@gmail.com> wrote:
where can i find all these kind of parameters?

Michael DeHaan

unread,
Nov 28, 2013, 3:32:13 PM11/28/13
to ansible...@googlegroups.com
Often easier to just start a new play;

hosts: group1:!group2

Targets all hosts in group1 that are not in group2


--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
Michael DeHaan <mic...@ansibleworks.com>
CTO, AnsibleWorks, Inc.
http://www.ansibleworks.com/

oliver bril

unread,
Nov 28, 2013, 3:56:19 PM11/28/13
to ansible...@googlegroups.com

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
Reply all
Reply to author
Forward
0 new messages