How to execute tasks based on group names in ansible

2,615 views
Skip to first unread message

Adithya Khamithkar

unread,
Nov 15, 2015, 6:47:56 AM11/15/15
to Ansible Project
Hi,

I would like to use the when condition to execute tasks based on group names in ansible.

I am using this code snipit

when: ({{group_names}} == "web-server")

But it always skips.

Can someone please correct me.

Matt Martz

unread,
Nov 15, 2015, 10:37:08 AM11/15/15
to ansible...@googlegroups.com
when: '"web-server" in group_names'

group_names is an array/list so you have to check if 'web-server' exists within it.
--
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.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/da3e21ec-38f5-44d2-ab6d-a1fc62f9866c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Matt Martz
@sivel
sivel.net

Message has been deleted

Stephen Granger

unread,
Nov 16, 2015, 6:00:07 PM11/16/15
to ansible...@googlegroups.com
Have you though about creating another play and just including those tasks under that play?

- hosts: all
  tasks:
    - name: do task A
...

- hosts: webservers
  tasks:
    - name: do tasks A only for webservers

I maybe oversimplifying your workflow but it could help decouple your tasks for re-usability later on.

On 15 November 2015 at 07:40, Adithya Khamithkar <nkadi...@gmail.com> wrote:
Thanks got it working!
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/YEKoGn-GsS0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.

To post to this group, send email to ansible...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
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.
To post to this group, send email to ansible...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Steve
Reply all
Reply to author
Forward
0 new messages