Cannot get when to work in playbook

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
    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/
    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.

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

dratzen-ratzen-uking yaml indents!

Thank you very much :slight_smile:

you brought new life

This really helped me. Thank you Brian