# Plays against different server groups in playbook

**URL:** <https://forum.ansible.com/t/plays-against-different-server-groups-in-playbook/19408>\
**Category:** Ansible Project\
**Tags:** windows\
**Created:** [October 1, 2015, 7:18pm UTC](https://forum.ansible.com/t/plays-against-different-server-groups-in-playbook/19408 "2015-10-01T19:18:38Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dyioulos](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dyioulos/32/8363_2.png) [@dyioulos](https://forum.ansible.com/u/dyioulos)\
**Post date:** [October 1, 2015, 7:18pm UTC](https://forum.ansible.com/t/plays-against-different-server-groups-in-playbook/19408/1 "2015-10-01T19:18:38Z")

</div>

I’m creating a playbook to update, then reboot, a group of windows servers (serversA). Prior to reboot, however, I have to stop a couple of services on another group of windows servers (serversB). This is what I’d like to happen when I run “ansible-playbook -l serversA playbook.yml”:

where playbook.yml:

- hosts: **serversA**  
gather\_facts: false  
tasks:

- name: win update

win\_updates:  
category: [‘SecurityUpdates’,‘CriticalUpdates’,‘Updates’,‘Tools’,‘DefinitionUpdates’,‘UpdateRollups’]  
register: reboot\_hint

- hosts: **serversB**  
gather\_facts: false  
tasks:

- name: check for XYZ service  
raw: sc query XYZ  
register: xyz\_hint  
failed\_when: xyz\_hint.rc not in [0,1060]

- name: stop XYZ and ABC services ← if XYZ service is installed, so is ABC

win\_service: name={{ item }} state=stopped  
with\_items: [“XYZ”, “ABC”]  
when: xyz\_hint.rc == 0

- hosts: **serversA**  
gather\_facts: false  
tasks:

- name: reboot server  
raw: ‘cmd /c shutdown /r /t 0’  
when: reboot\_hint.reboot\_required == true

Can I do this in a single playbook? If not (or if this is set up incorrectly, and I’m sure it is), then how?

Thanks!

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [October 1, 2015, 8:16pm UTC](https://forum.ansible.com/t/plays-against-different-server-groups-in-playbook/19408/2 "2015-10-01T20:16:10Z")

</div>

you can have multiple plays per playbook, that is actually how it is  
defined playbook = container for 1 or more plays.

---

<div class="post-metadata">

**Author:** ![Josh\_Smift1](https://avatars.discourse-cdn.com/v4/letter/j/bcef8e/32.png) [@Josh\_Smift1](https://forum.ansible.com/u/Josh_Smift1)\
**Post date:** [October 1, 2015, 8:22pm UTC](https://forum.ansible.com/t/plays-against-different-server-groups-in-playbook/19408/3 "2015-10-01T20:22:54Z")

</div>

> you can have multiple plays per playbook, that is actually how it is  
> defined playbook = container for 1 or more plays.

I was just thinking about something that this seems like an opportune time  
to ask about:

It seems that if you have multiple plays, some of which target different  
hosts, and if all of the hosts in \*one play\* fail, that fails the entire  
playbook. Is that still true, and is there a way to overide that behavior?  
(I did a bit of searching, and saw some questions in the archive from a  
year or more ago which implied that there wasn't a way to override it.)

Our particular use case is that we have a playbook to check that our  
systems are in synch with how we expect them to be, with a play for each  
type of system, and sometimes one of those plays will fail for some minor  
intermittent reason -- it only targets one host and that host is down,  
etc. It'd be nice if the rest of the playbook could continue in that case.

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-Josh (jbs@care.com)

This email is intended for the person(s) to whom it is addressed and may contain information that is PRIVILEGED or CONFIDENTIAL. Any unauthorized use, distribution, copying, or disclosure by any person other than the addressee(s) is strictly prohibited. If you have received this email in error, please notify the sender immediately by return email and delete the message and any attachments from your system.

---

<div class="post-metadata">

**Author:** ![dyioulos](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dyioulos/32/8363_2.png) [@dyioulos](https://forum.ansible.com/u/dyioulos)\
**Post date:** [October 2, 2015, 1:29pm UTC](https://forum.ansible.com/t/plays-against-different-server-groups-in-playbook/19408/4 "2015-10-02T13:29:14Z")

</div>

Hi, Brian.

Yes, I understand about the playbook running one or more plays. What I didn’t understand (and this is another of my embarrassing mistakes) is that I shouldn’t have identified any servers or groups when running the playbook, as in “ansible-playbook -l serversA playbook.yml” but, rather, run it thusly, “ansible-playbook playbook.yml”. That, of course, let’s Ansible apply the plays to the servers or groups that are specified in the plays. Arrgh. Hope I’m not using up all of my goodwill on the list.

Dimitri

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [October 2, 2015, 2:07pm UTC](https://forum.ansible.com/t/plays-against-different-server-groups-in-playbook/19408/5 "2015-10-02T14:07:46Z")

</div>

Dimitri,

not sure what you mean by "ansible-playbook -l serversA playbook.yml"

don't worry about using up goodwill, i never had any to begin with ....

---

<div class="post-metadata">

**Author:** ![dyioulos](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dyioulos/32/8363_2.png) [@dyioulos](https://forum.ansible.com/u/dyioulos)\
**Post date:** [October 2, 2015, 2:58pm UTC](https://forum.ansible.com/t/plays-against-different-server-groups-in-playbook/19408/6 "2015-10-02T14:58:49Z")

</div>

Hey, Brian.

I was using the “l” switch, thereby limiting the playbook run to a subset of servers. In this case, there was no need for such limiting (and, in fact, it caused the playbook to work incorrectly). How stupid of me. So, allow me to post the entire playbook:
