title: ansible include_if_exists
body: <p>I'm looking for a way to conditionally include a file in an Ansible play, if the file exists. Using "include" unfortunately throws a fatal error if the file doesn't exist. I'm looping through a bunch of packages and installing them and I want to check for an optional config file for each package. See simplified example below:</p>
  
  <pre><code>---
  - name: Basic setup of an Ubuntu box
    hosts: all
    vars:
      packages:
        - ack-grep
        - vim
        - zsh
        - htop
        - openssh-server
        - cowsay
    tasks:
      - name: Run package configuration
        action: apt name=$item
        include: "packages/${item}.yml"
        with_items: $packages
  </code></pre>
  
  <p>As soon as the script tries to include a file that doesn't exist, it stops with an error.
  I'm sure I'm just trying to do something in the wrong way, but I've been at this for hours and tried everything I can think of, with no results.</p>