# action dependent on RHEL release

**URL:** <https://forum.ansible.com/t/action-dependent-on-rhel-release/11766>\
**Category:** Ansible Project\
**Tags:** rhel\
**Created:** [August 6, 2012, 12:46pm UTC](https://forum.ansible.com/t/action-dependent-on-rhel-release/11766 "2012-08-06T12:46:53Z")\
**Posts on this page:** 10\
**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:** [August 6, 2012, 12:46pm UTC](https://forum.ansible.com/t/action-dependent-on-rhel-release/11766/1 "2012-08-06T12:46:53Z")

</div>

Simply stated. Is there a shorter and more elegant way to do the following?

-------\>8----------\>8------------------

&nbsp;&nbsp;- name: Fix the MX for rhel61  
&nbsp;&nbsp;&nbsp;&nbsp;action: command postconf -e "relayhost=mx.gnuf.com"  
&nbsp;&nbsp;&nbsp;&nbsp;only\_if: "'$ansible\_distribution\_version' == '6.1'"

&nbsp;&nbsp;- name: Fix the MX for rhel62  
&nbsp;&nbsp;&nbsp;&nbsp;action: command postconf -e "relayhost=mx.gnuf.com"  
&nbsp;&nbsp;&nbsp;&nbsp;only\_if: "'$ansible\_distribution\_version' == '6.2'"

&nbsp;&nbsp;- name: Fix the MX for rhel63  
&nbsp;&nbsp;&nbsp;&nbsp;action: command postconf -e "relayhost=mx.gnuf.com"  
&nbsp;&nbsp;&nbsp;&nbsp;only\_if: "'$ansible\_distribution\_version' == '6.3'"

&nbsp;&nbsp;- name: Fix the MX for rhel54  
&nbsp;&nbsp;&nbsp;&nbsp;action: command sed -i 's/DS/DSmx.gnuf.com/' /etc/mail/sendmail.cf  
&nbsp;&nbsp;&nbsp;&nbsp;only\_if: "'$ansible\_distribution\_version' == '5.4'"

&nbsp;&nbsp;- name: Fix the MX for rhel57  
&nbsp;&nbsp;&nbsp;&nbsp;action: command sed -i 's/DS/DSmx.gnuf.com/' /etc/mail/sendmail.cf  
&nbsp;&nbsp;&nbsp;&nbsp;only\_if: "'$ansible\_distribution\_version' == '5.7'"

--------8\<-----------8\<------------------

/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:** [August 6, 2012, 12:48pm UTC](https://forum.ansible.com/t/action-dependent-on-rhel-release/11766/2 "2012-08-06T12:48:19Z")

</div>

There is not.

-- Michael

---

<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:** [August 6, 2012, 12:53pm UTC](https://forum.ansible.com/t/action-dependent-on-rhel-release/11766/3 "2012-08-06T12:53:27Z")

</div>

Thanks, Michael!

If someone makes one up, let me know.

/andreas

---

<div class="post-metadata">

**Author:** ![Ernest0x](https://avatars.discourse-cdn.com/v4/letter/e/ed655f/32.png) [@Ernest0x](https://forum.ansible.com/u/Ernest0x)\
**Post date:** [August 6, 2012, 1:02pm UTC](https://forum.ansible.com/t/action-dependent-on-rhel-release/11766/4 "2012-08-06T13:02:50Z")

</div>

Does only\_if take python expressions like  
"'$ansible\_distribution\_version' in ['6.1', '6.2', '6.3']" ?  
And if not, should it?

---

<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:** [August 6, 2012, 1:07pm UTC](https://forum.ansible.com/t/action-dependent-on-rhel-release/11766/5 "2012-08-06T13:07:20Z")

</div>

I'm suspecting it probably will not happen.

While we could continue to introduce language primatives, I generally  
want the language to remain minimal. If we end up with ternaries and  
case statements, we're almost programming in YAML, and I explicitly  
did not  
want this to be a programming language.

For instance, the best way to not run some tasks on a particular group  
is to not talk to that group of systems 🙂

--Michael

---

<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:** [August 6, 2012, 1:09pm UTC](https://forum.ansible.com/t/action-dependent-on-rhel-release/11766/6 "2012-08-06T13:09:05Z")

</div>

> > > /andreas
> 
> Does only\_if take python expressions like  
> "'$ansible\_distribution\_version' in ['6.1', '6.2', '6.3']" ?  
> And if not, should it?

This is covered in the docs under "Conditional Expressions"

[http://ansible.github.com/playbooks2.html](http://ansible.github.com/playbooks2.html)

"This is easy to do in Ansible, with the only\_if clause, which  
actually is a Python expression."

---

<div class="post-metadata">

**Author:** ![Ernest0x](https://avatars.discourse-cdn.com/v4/letter/e/ed655f/32.png) [@Ernest0x](https://forum.ansible.com/u/Ernest0x)\
**Post date:** [August 6, 2012, 1:29pm UTC](https://forum.ansible.com/t/action-dependent-on-rhel-release/11766/7 "2012-08-06T13:29:15Z")

</div>

Well, I personally find the 'in' syntax so expressive that it 'does not  
look much like coding' to me. On the other hand, I would agree that  
proper grouping of hosts is most of the time the best way to reduce  
repetitive statements.  
In all cases, it should be included in the documentation what kind of  
python expressions and operators are supported by the 'only\_if' option.

---

<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:** [August 6, 2012, 1:32pm UTC](https://forum.ansible.com/t/action-dependent-on-rhel-release/11766/8 "2012-08-06T13:32:46Z")

</div>

> In all cases, it should be included in the documentation what kind of  
> python expressions and operators are supported by the ‘only\_if’ option.

Anything that evaluates to a boolean is fair game, though of course the computation is performed on the machine where ansible is installed.

---

<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:** [August 6, 2012, 1:35pm UTC](https://forum.ansible.com/t/action-dependent-on-rhel-release/11766/9 "2012-08-06T13:35:42Z")

</div>

I'm not sure I get that, since I don't know what a valid pyton  
expression is.

/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:** [August 6, 2012, 1:59pm UTC](https://forum.ansible.com/t/action-dependent-on-rhel-release/11766/10 "2012-08-06T13:59:10Z")

</div>

> I’m not sure I get that, since I don’t know what a valid pyton  
> expression is.

Anything that returns a value is essentially an expression.

This means basically anything is fair game.
