# When condition

**URL:** <https://forum.ansible.com/t/when-condition/21312>\
**Category:** Ansible Project\
**Created:** [April 29, 2016, 10:08am UTC](https://forum.ansible.com/t/when-condition/21312 "2016-04-29T10:08:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Suresh\_Uppu](https://avatars.discourse-cdn.com/v4/letter/s/ee59a6/32.png) [@Suresh\_Uppu](https://forum.ansible.com/u/Suresh_Uppu)\
**Post date:** [April 29, 2016, 10:08am UTC](https://forum.ansible.com/t/when-condition/21312/1 "2016-04-29T10:08:50Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Johannes\_Kastl](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@Johannes\_Kastl](https://forum.ansible.com/u/Johannes_Kastl)\
**Post date:** [May 3, 2016, 4:52am UTC](https://forum.ansible.com/t/when-condition/21312/2 "2016-05-03T04:52:50Z")

</div>

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:

&nbsp;&nbsp;&nbsp;&nbsp;- name: installing python setuptools on RedHat  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;become: yes  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;become\_method: sudo  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;yum: name=python-setuptools state=latest  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;when: ansible\_os\_family == "RedHat"

&nbsp;&nbsp;&nbsp;&nbsp;- name: installing python setuptools on SLES  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;become: yes  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;become\_method: sudo  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;zypper: name=python-setuptools state=latest  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;when: ansible\_os\_family == "SLES"

Johannes
