title: Ansible Playbook - Synchronize module - Register variable and with_items
body: <p>I'm trying to write a playbook that will rsync the folders from source to target after a database refresh. Our Peoplesoft HR application also requires a filesystem refresh along with database. I'm new to ansible and not an expert with python. I've written this but my playbook fails if any of the with_items doesn't exist. I'd like to use this playbook for all apps and the folders may differ between apps. How can I skip the folders that doesn't exist in source. I'm passing <code>{{ target }}</code> at command line.</p>
  
  <pre><code>---
  - hosts: '&lt;hostname&gt;'
    remote_user: &lt;user&gt;
  
    tasks:
      - shell: ls -l /opt/custhome/prod/
        register: folders
  
      - name:  "Copy PROD filesystem to target"
        synchronize:
          src: "/opt/custhome/prod/{{ item }}"
          dest: "/opt/custhome/dev/"
          delete: yes
        when: "{{ folders == item }}"
        with_items:
          - 'src/cbl/'
          - 'sqr/'
          - 'bin/'
          - 'NVISION/'
  </code></pre>
  
  <p>In this case, NVISION doesn't exist in HR app but it does in FIN app. But the playbook is failing coz that folder doesn't exist in source.</p>