When condition

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.

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