# Multiple conditionals

**URL:** <https://forum.ansible.com/t/multiple-conditionals/11979>\
**Category:** Ansible Project\
**Created:** [October 15, 2012, 8:45am UTC](https://forum.ansible.com/t/multiple-conditionals/11979 "2012-10-15T08:45:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andreas\_Davour](https://avatars.discourse-cdn.com/v4/letter/a/bcef8e/32.png) [@Andreas\_Davour](https://forum.ansible.com/u/Andreas_Davour)\
**Post date:** [October 15, 2012, 8:45am UTC](https://forum.ansible.com/t/multiple-conditionals/11979/1 "2012-10-15T08:45:54Z")

</div>

Hi

While I understand you can in theory put any valid python expression in a playbook, to set a variable, I'm wondering about the elegant and intended way to accomplish something like running a playbook against all webservers (grouped in the inventory I guess), which are of a specific system release and \*also\* have a specific service running (or maybe a specific file exists in the file system tree)?

My main focus is to understand how to satisfy both those two conditions in a elegant way.

/andreas

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [October 15, 2012, 12:26pm UTC](https://forum.ansible.com/t/multiple-conditionals/11979/2 "2012-10-15T12:26:45Z")

</div>

Ok, so the primary conditional mechanism in Ansible is still the host selector.

I would create a play for webservers by group, definitely.

You can of course use the 'command/shell' module with 'register' to  
set a variable that checks whether the service is running and use  
"only\_if: ${command\_result.rc} == 0" and so on.

If you are already writing your own facts, you could also put that  
service runningness into the fact module.

Since it's a python expression you can combine only\_ifs with 'and' statements.

---

<div class="post-metadata">

**Author:** ![Andreas\_Davour](https://avatars.discourse-cdn.com/v4/letter/a/bcef8e/32.png) [@Andreas\_Davour](https://forum.ansible.com/u/Andreas_Davour)\
**Post date:** [October 15, 2012, 12:41pm UTC](https://forum.ansible.com/t/multiple-conditionals/11979/3 "2012-10-15T12:41:26Z")

</div>

Excellent. Then I get how it's supposed to work. Thanks.

-andreas
