title: Skip Ansible task when variable not defined
body: <p>I have the following task in a playbook:</p>
  
  <pre><code>- name: task xyz  
    copy:  
      src="{{ item }}"  
      dest="/tmp/{{ item }}"  
    with_items: "{{ y.z }}"  
    when: y.z is defined  
  </code></pre>
  
  <p><code>y.z</code> is not defined, so I'm expecting the task to be skipped. Instead, I receive:</p>
  
  <pre><code>FAILED! =&gt; {"failed": true, "msg": "'dict object' has no attribute 'z'"
  </code></pre>
  
  <p>I have found:
  <a href="https://stackoverflow.com/questions/30119973/how-to-run-a-task-when-variable-is-undefined-in-ansible">How to run a task when variable is undefined in ansible?</a>
  but it seems I implemented just that. What am I doing wrong here?</p>