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:
`
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:
`
anyone able to help ?
- 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")
This logic seems wrong to me. With
"msg": "distro is CentOS and version is 6"
then your when turns into
when: (False and False) or (True and True)
aka
when: False or True
aka True. Right?
I think you want something more like
when: NOT (CentOS 6 or Ubuntu 14)
than like
when: (not CentOS 6) or (not Ubuntu 14)
Because you're always going to be not one of those things -- you need to
negate the whole or.
-Josh (jbs@care.com)
This email is intended for the person(s) to whom it is addressed and may contain information that is PRIVILEGED or CONFIDENTIAL. Any unauthorized use, distribution, copying, or disclosure by any person other than the addressee(s) is strictly prohibited. If you have received this email in error, please notify the sender immediately by return email and delete the message and any attachments from your system.
Thanks for clarifying that for me Josh.
What I did was create a variable that contains the supported distributions and have my when condition check against it:
`
vars:
supported_distros: “{{ ansible_distribution }} {{ ansible_distribution_major_version }}”
tasks:
That did the tricks!