action dependent on RHEL release

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

------->8---------->8------------------

  - name: Fix the MX for rhel61
    action: command postconf -e "relayhost=mx.gnuf.com"
    only_if: "'$ansible_distribution_version' == '6.1'"

  - name: Fix the MX for rhel62
    action: command postconf -e "relayhost=mx.gnuf.com"
    only_if: "'$ansible_distribution_version' == '6.2'"

  - name: Fix the MX for rhel63
    action: command postconf -e "relayhost=mx.gnuf.com"
    only_if: "'$ansible_distribution_version' == '6.3'"

  - name: Fix the MX for rhel54
    action: command sed -i 's/DS/DSmx.gnuf.com/' /etc/mail/sendmail.cf
    only_if: "'$ansible_distribution_version' == '5.4'"

  - name: Fix the MX for rhel57
    action: command sed -i 's/DS/DSmx.gnuf.com/' /etc/mail/sendmail.cf
    only_if: "'$ansible_distribution_version' == '5.7'"

--------8<-----------8<------------------

/andreas

There is not.

-- Michael

Thanks, Michael!

If someone makes one up, let me know.

/andreas

Does only_if take python expressions like
"'$ansible_distribution_version' in ['6.1', '6.2', '6.3']" ?
And if not, should it?

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 :slight_smile:

--Michael

/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

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

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.

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.

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

/andreas

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.