title: In Ansible loop, test existence of files from registered results
body: <p>I have several files that I need to backup in different directories.  I have tried the code below and not working for me.</p>
  
  <pre><code>  vars:
      file_vars:
        - {name: /file1}
        - {name: /etc/file2}
        - {name: /etc/file/file3}
  
    tasks:
  
    - name: "Checking if config files exists"
      stat:
        path: "{{ item.name }}"
      with_items: "{{ file_vars }}"
      register: stat_result
  
    - name: Backup Files
      copy: src={{ item.name }} dest={{ item.name }}{{ ansible_date_time.date }}.bak
      with_items: "{{ file_vars }}"
      remote_src: yes
      when: stat_result.stat.exists == True
  </code></pre>