# question about setting variables

**URL:** <https://forum.ansible.com/t/question-about-setting-variables/12520>\
**Category:** Ansible Project\
**Tags:** rhel\
**Created:** [March 18, 2013, 12:12am UTC](https://forum.ansible.com/t/question-about-setting-variables/12520 "2013-03-18T00:12:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dale\_Quigg](https://avatars.discourse-cdn.com/v4/letter/d/cab0a1/32.png) [@Dale\_Quigg](https://forum.ansible.com/u/Dale_Quigg)\
**Post date:** [March 18, 2013, 12:12am UTC](https://forum.ansible.com/t/question-about-setting-variables/12520/1 "2013-03-18T00:12:09Z")

</div>

Hi,

I've just started working with Ansible and first want to say, "Nice  
work Michael!". I was able to understand the concepts and get a  
'hello world' example running in hours. I've been looking a Puppet/  
Chef off and on over the last year and never really "got it".

I would like to create a task (or playbook) that installs EPEL on a  
RHEL/CentOS/SciLinux systems. So, first I need to ensure I'm on an  
EPEL compatible OS. I tried (incomplete)

---

<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:** [March 18, 2013, 1:30pm UTC](https://forum.ansible.com/t/question-about-setting-variables/12520/2 "2013-03-18T13:30:52Z")

</div>

Quoting can be fun with "only\_if" which is why the "when\_" forms  
exist, but the easiest way to do it is really to use "group slicing"  
using the only\_if module.  
It is more idiomatic and keeps you from writing code, and makes  
playbooks more readable.

Remember that a playbook is a list of plays, so you can have one play  
that targets everything, one that targets some specific thing,  
followed up by another that targets everything.  
Thus, in many cases, you can avoid using conditionals this way.

[http://ansible.cc/docs/bestpractices.html#operating-system-and-distribution-variance](http://ansible.cc/docs/bestpractices.html#operating-system-and-distribution-variance)

Thus you could easily make groups for

${ansible\_distribution}-${ansible\_distribution\_version}

and do:

hosts: CentOS-5.4:CentOS-5.5

For instance, to target just hosts running CentOS-5.4 and 5.5

I don't believe we imported the "re" module in the right scope yet to  
do regular expressions in the conditionals, but I'll have to check on  
that.
