I am trying to use the fail module at the very beginning of my playbook to 
check if the target server is a specific distribution and version. This way 
I can stop the playbook from running early on before any making any chances.

playbook:
---
- hosts: all

  tasks:
    - debug: msg='distro is {{ ansible_distribution }} and version is {{ 
ansible_distribution_major_version }}'

    - name: check if target server is CentOS 6
      fail: msg='You have attempted to run this playbook against an 
unsupported platform!'
      when: (ansible_distribution != "CentOS" and 
ansible_distribution_major_version != "6")

    - name: check if target server is CentOS 6 or Ubuntu 14
      fail: msg='unsupported platform detected!'
      when: (ansible_distribution != "CentOS" and 
ansible_distribution_major_version != "6") or (ansible_distribution != 
"Ubuntu" and ansible_distribution_major_version != "14")

    - debug: msg="Supported platform detected!"

playbook execution:

ansible-playbook test.yml -i inventory -u root -k
SSH password: 

PLAY [all] 
******************************************************************** 

GATHERING FACTS 
*************************************************************** 
ok: [192.168.245.11]

TASK: [debug msg='distro is {{ ansible_distribution }} and version is {{ 
ansible_distribution_major_version }}'] *** 
ok: [192.168.245.11] => {
    "msg": "distro is CentOS and version is 6"
}

TASK: [check if target server is CentOS 6] *********************** 
skipping: [192.168.245.11]

TASK: [check if target server is CentOS 6 or Ubuntu 14] 
*********************** 
failed: [192.168.245.11] => {"failed": true}
msg: unsupported platform detected!

FATAL: all hosts have already failed -- aborting

PLAY RECAP 
******************************************************************** 
           to retry, use: --limit @/tmp/test.retry

192.168.245.11               : ok=2    changed=0    unreachable=0    failed=
1   


Where am I going wrong ?

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/f20162a7-f857-4a88-be82-77335f04c9c3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to