Something Similar to Ruby's Case Operator

49 views
Skip to first unread message

Navid Paya

unread,
May 10, 2014, 10:09:12 AM5/10/14
to ansible...@googlegroups.com
Hi all
We have a mix of Debian and Redhat in our infrastructure so basically for every single step, I have to add two of the same operators for both of them, like this:

- name: Install prerequisite packages
  action: apt pkg={{item}} state=installed
  with_items:
    - sysstat
  when: ansible_os_family == 'Debian'

- name: Install prerequisite packages
  action: yum pkg={{item}} state=installed
  with_items:
    - sysstat
  when: ansible_os_family == 'RedHat'

Does Ansible have an operator similar to the case operator in Ruby or Chef and Puppet for that matter?

Michael DeHaan

unread,
May 12, 2014, 11:11:02 AM5/12/14
to ansible...@googlegroups.com
There is no case statement in ansible.

You can look into "group_by" when eliminating repeated conditionals if this works for you.

- hosts: webservers
  tasks:
     - group_by: key=os-{{ ansible_os_family }}

- hosts:webservers:&os-Debian
  tasks:
      - ...

etc




--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/8698728f-b185-4ba2-9b1f-b2bee476bba9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages