When condition

14 views
Skip to first unread message

Suresh Uppu

unread,
Apr 29, 2016, 9:42:55 AM4/29/16
to Ansible Project
Hi,

This is Suresh. I am new to Ansible.

I have a query, Can I please ask any one to clarify this.

I am using when: condition. 

The below one is working fine.

file copy is working fine based on distribution. didnt get any error.
"
    - name: copying clinet install zip to server
      become: yes
      become_method: sudo
      copy: src=/root/Desktop/clinetinstall.zip dest=clientproducts/Install.zip
      when: ansible_distribution  == "CentOS"
      copy: src=/root/Desktop/myfile  dest=clientproducts/myfile
      when: ansible_distribution  == "RedHat"

"

I expected the same when installing python-setuptools on agent machine.

    - name: installing python setuptools
      become: yes
      become_method: sudo
      yum: name=python-setuptools  state=latest
      when: ansible_os_family == "RedHat"
      zypper: name=python-setuptools  state=latest
      when: ansible_os_family == "SLES"

But getting compilation error.

what is the problem with the lines in playbook?

Best Regards,
Suresh.

Johannes Kastl

unread,
May 3, 2016, 3:21:22 AM5/3/16
to ansible...@googlegroups.com
On 29.04.16 12:08 'Suresh Uppu' via Ansible Project wrote:

> - name: installing python setuptools
> become: yes
> become_method: sudo
> yum: name=python-setuptools state=latest
> when: ansible_os_family == "RedHat"
> zypper: name=python-setuptools state=latest
> when: ansible_os_family == "SLES"
>
> But getting compilation error.

I have not tested this, but maybe the error is caused by the fact,
that zypper module does not work/exist on RedHat and yum module does
not exist on SLES?

Split it into two tasks:

- name: installing python setuptools on RedHat
become: yes
become_method: sudo
yum: name=python-setuptools state=latest
when: ansible_os_family == "RedHat"

- name: installing python setuptools on SLES
become: yes
become_method: sudo
zypper: name=python-setuptools state=latest
when: ansible_os_family == "SLES"

Johannes


signature.asc
Reply all
Reply to author
Forward
0 new messages