title: Ansible: Multiple and/or conditionals in when clause
body: <p>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.</p>
  
  <p>I run the playbook with the following commands and define the variables through extended variables option (-e)</p>
  
  <p><code>ansible-playbook site.yml -i inventory --ask-vault -u (username) -e "security=true restart=true" -k -K
  </code></p>
  
  <p>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:</p>
  
  <pre><code>- 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" 
  </code></pre>
  
  <p>Ive tried all of the following combinations:</p>
  
  <p><code>when: (ansible_os_family == "RedHat") and (security is defined or kernel is defined or specified_packages is defined)</code></p>
  
  <p><code>when: (ansible_os_family == "RedHat") and (security == true or kernel == true or specified_packages == true )</code> &lt;- this case throws a not defined error because i don't define all variables every time i run the playbook</p>
  
  <p><code>when: ansible_os_family == "RedHat"
   when: security is defined or kernel is defined or specified_packages is defined</code></p>
  
  <p><strong>Note:</strong> I am aware and have used an extra variable such as "skip" to skip this task and use the when clause <code>when: ansible_os_family == "RedHat" and skip is not defined</code> but would prefer not have my users need to use an extra variable just to skip this default action.</p>
  
  <p>I also am not using tags as I am gathering a list of packages before and after the upgrade to compare and report in the end so I wont be able to run those as they are local action commands. This is why I'm using one role with multiple tasks turned on and off via extended variables. I am open to any suggestion that rewrites the playbook in a more efficient way as I am sort of a noob.</p>