# Cannot get when to work in playbook

**URL:** <https://forum.ansible.com/t/cannot-get-when-to-work-in-playbook/22807>\
**Category:** Ansible Project\
**Tags:** rhel\
**Created:** [October 17, 2016, 5:15pm UTC](https://forum.ansible.com/t/cannot-get-when-to-work-in-playbook/22807 "2016-10-17T17:15:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kane\_Kennedy](https://avatars.discourse-cdn.com/v4/letter/k/b9e5f3/32.png) [@Kane\_Kennedy](https://forum.ansible.com/u/Kane_Kennedy)\
**Post date:** [October 17, 2016, 5:15pm UTC](https://forum.ansible.com/t/cannot-get-when-to-work-in-playbook/22807/1 "2016-10-17T17:15:35Z")

</div>

Hi can anyone help, this is doing my nut in.

I cannot get the correct repo to install dependent on the OS family and release, I have 7 repos and need to identify RHEL, SL and Oracle v 5, 6 (x86 or x64) and 7.  
All our servers patch from local repositories, none are allowed direct access to the outside world.  
As you can see i have tried the when statement in the two ways I have seen in the docs. Removing the WHEN statement installs the repo file fine, as you can appreciate I dont want to be installing incorrect repo files onto production systems.

[root@xxxxx]# ansible --version  
ansible 2.1.2.0  
config file = /etc/ansible/roles/xxxx/ansible.cfg  
configured module search path = Default w/o overrides

playbook - snipped

- hosts: patch-test  
tasks:

- debug:  
msg: “System {{ inventory\_hostname }} is {{ ansible\_distribution }} major vession {{ ansible\_distribution\_major\_version }}”

- name: Enable Scientific Linux 6 x86 local repo  
yum\_repository:  
name: Scientific\_Linux\_6\_x86\_Local  
description: Scientific\_Linux\_6-32  
file: Scientific\_linux  
baseurl: [http://burkrules/repos/sl6-32](http://burkrules/repos/sl6-32)  
gpgcheck: no  
when: ansible\_distribution == “Scientific” and ansible\_distribution\_major\_version == “6” and ansible\_architecture == “i386”

- name: Enable Scientific Linux 7 local repo  
yum\_repository:  
name: Scientific\_Linux\_7\_Local  
description: Scientific\_Linux\_7-64  
file: Scientific\_linux  
baseurl: [http://berkrules/repos/sl7-64/](http://berkrules/repos/sl7-64/)  
gpgcheck: no  
when:

- ansible\_distribution == ‘Scientific’

- ansible\_distribution\_major\_version == ‘7’

Output - snipped

PLAY [patch-test] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

TASK [setup] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [XXTS2]

TASK [debug] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [XXTS2] =\> {  
“msg”: “System XXXTS2 is Scientific major vession 7”  
}

TASK [Enable Scientific Linux 6 x86 local repo] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
fatal: [XXTS2]: FAILED! =\> {“changed”: false, “failed”: true, “msg”: “unsupported parameter for module: when”}

NO MORE HOSTS LEFT \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
to retry, use: --limit @…

Many thanks for any help.

Kane.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [October 17, 2016, 5:28pm UTC](https://forum.ansible.com/t/cannot-get-when-to-work-in-playbook/22807/2 "2016-10-17T17:28:22Z")

</div>

You are indenting when: too far, it is part of the task, not the module options.

---

<div class="post-metadata">

**Author:** ![Kane\_Kennedy](https://avatars.discourse-cdn.com/v4/letter/k/b9e5f3/32.png) [@Kane\_Kennedy](https://forum.ansible.com/u/Kane_Kennedy)\
**Post date:** [October 18, 2016, 9:25am UTC](https://forum.ansible.com/t/cannot-get-when-to-work-in-playbook/22807/3 "2016-10-18T09:25:02Z")

</div>

dratzen-ratzen-uking yaml indents!

Thank you very much 🙂

---

<div class="post-metadata">

**Author:** ![Massimiliano\_Fermo](https://avatars.discourse-cdn.com/v4/letter/m/b5a626/32.png) [@Massimiliano\_Fermo](https://forum.ansible.com/u/Massimiliano_Fermo)\
**Post date:** [February 13, 2017, 1:00am UTC](https://forum.ansible.com/t/cannot-get-when-to-work-in-playbook/22807/4 "2017-02-13T01:00:31Z")

</div>

**you brought new life**

---

<div class="post-metadata">

**Author:** ![Dinesh\_Patra](https://avatars.discourse-cdn.com/v4/letter/d/e480ec/32.png) [@Dinesh\_Patra](https://forum.ansible.com/u/Dinesh_Patra)\
**Post date:** [March 10, 2017, 6:20pm UTC](https://forum.ansible.com/t/cannot-get-when-to-work-in-playbook/22807/5 "2017-03-10T18:20:51Z")

</div>

This really helped me. Thank you Brian
