On 30. juni 2017 19:10, ajay jiwanand wrote:
  Im posting my stack overflow question as it is much more clear:


Ask Question <https://stackoverflow.com/questions/ask>
up vote0down votefavorite
<https://stackoverflow.com/questions/44838421/ansible-multiple-an-or-conditionals-in-when-clause/44839565?noredirect=1#>

I am having issues when trying to use multiple and/or conditionals in a
when statement to decide whether a task needs to be ran or not. Basically I
am making a playbook to do automated system patching with options for
security patches, kernel only patches and to specify packages in a var file.

I run the playbook with the following commands and define the variables
through extended variables option (-e)

ansible-playbook site.yml -i inventory --ask-vault -u (username)-e
"security=true restart=true" -k -K

By default the playbook will update every package on the system except
kernel but I would like to skip that action if I specify any of a few
variables. The code I have is the following:

- name: Update all packages yum: name: "*" state: latest exclude: "kernel*"
when: security is not defined or kernel is not defined or
specified_packages is not defined and ansible_os_family == "RedHat"

Your last three posted have different explanation of what you are trying to achieve, but according to this post I think you are looking for this

when: not (security is defined or kernel is defined or specified_packages is defined) and ansible_os_family == "RedHat"

This only run on RedHat when none of the variables is set.


--
Kai Stian Olstad

--
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 ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/b46215dd-af25-2320-99d1-154548b3bbf7%40olstad.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to