title: Puppet : file resource only if file exists
body: <p>What I want to do is quite simple :</p>
  
  <p>1.</p>
  
  <p>Copy <code>/source/file</code> to <code>/target/file</code>. I achieve this using the following:</p>
  
  <pre><code>file { 'my_file_copy':
    ensure   =&gt; file,
    source   =&gt; 'file:/source/file',
    path     =&gt; "/target/file",
  }
  </code></pre>
  
  <p>2.</p>
  
  <p>However, if file <code>/source/file</code> does not exist, I do NOT want it to perform this task.</p>
  
  <p>I am really struggling with this logic. I attempted the solution below but it throws exceptions during puppet run.</p>
  
  <p><a href="https://stackoverflow.com/questions/31463506/puppet-if-one-file-exists-then-copy-another-file-over">puppet: if one file exists then copy another file over</a></p>
  
  <p>Is there a better way of achieving this task ?
  Ideally, I would like to only use "file" and avoid using "exec". But at this point I would settle for a solution !</p>