Cannot get when to work in playbook

698 views
Skip to first unread message

Kane Kennedy

unread,
Oct 17, 2016, 1:15:35 PM10/17/16
to Ansible Project
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
     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
     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.

Brian Coca

unread,
Oct 17, 2016, 1:28:35 PM10/17/16
to ansible...@googlegroups.com
You are indenting when: too far, it is part of the task, not the module options.


----------
Brian Coca

Kane Kennedy

unread,
Oct 18, 2016, 5:25:02 AM10/18/16
to Ansible Project
dratzen-ratzen-uking yaml indents!

Thank you very much :)

Massimiliano Fermo

unread,
Feb 13, 2017, 9:07:12 AM2/13/17
to Ansible Project
you brought new life

Dinesh Patra

unread,
Mar 11, 2017, 7:34:41 PM3/11/17
to Ansible Project
This really helped me. Thank you Brian
Reply all
Reply to author
Forward
0 new messages