title: Check the defined variable is empty or not in Ansible
body: <pre><code>- hosts: localhost
    vars:
             files_list:
             #it may contain the file_list like 
             #file_list: 
             #     - "file*"
    tasks: 
         - name: copy
           copy:
               src: "{{item}}"
               dest: "/tmp/"
           with_fileglob: "{{files_list}}"
           when: files != None
  </code></pre>
  
  <p>I want to copy some multiple files with a specific pattern from the files_list. <strong>but sometimes the file_list may be empty</strong>. so <strong>how to check if the file_list is empty</strong> I have tried above code but it doesn't work. it is giving me following error</p>
  
  <pre><code>The full traceback is:&lt;br&gt;
  Traceback (most recent call last):&lt;br&gt;
    File "/usr/lib/python2.7/site-packages/ansible/executor/task_executor.py", line 104, in run&lt;br&gt;
      items = self._get_loop_items()&lt;br&gt;
    File "/usr/lib/python2.7/site-packages/ansible/executor/task_executor.py", line 245, in _get_loop_items&lt;br&gt;
      items = wrap_var(mylookup.run(terms=loop_terms, variables=self._job_vars, wantlist=True))&lt;br&gt;
    File "/usr/lib/python2.7/site-packages/ansible/plugins/lookup/fileglob.py", line 60, in run&lt;br&gt;
      term_file = os.path.basename(term)&lt;br&gt;
    File "/usr/lib64/python2.7/posixpath.py", line 121, in basename&lt;br&gt;
      i = p.rfind('/') + 1&lt;br&gt;
  AttributeError: 'NoneType' object has no attribute 'rfind'&lt;br&gt;
  fatal: [machine1.kirusa.com]: FAILED! =&gt; {&lt;br&gt;
      "msg": "Unexpected failure during module execution.", &lt;br&gt;
      "stdout": ""&lt;br&gt;
  }
  </code></pre>
  
  <p>Can you also explain whats this mean.
  thank you in advance.</p>