title: Ansible loop with conditional statement
body: <p>Is it possible to have loop with conditional statement in Ansible? What I want is to find whether a path exists for a specific file. If it exists, to perform a loop, and only for that specific file to see conditional statement. Code sample below</p>
  <pre class="lang-yaml prettyprint-override"><code>  - name: File exist
      stat:
        path: &lt;path to the file or directory you want to check&gt;
      register: register_name
  
  - name: Copy file
    copy:
      src: '{{ item }}'
      dest: '&lt;destination path&gt;'
    with_fileglob:
      - ../spring.jar
      - &lt;perform if statement. if register_name.stat.exists, ../info.txt, else dont copy this info.txt &gt;
  
  
  # ... few other task with loop instead of with_fileglob
  </code></pre>