title: Checking if a directory exists before copying in Puppet
body: <p>I am trying to get a backup of a subdirectory before deleting the parent directory by copying the subdirectory into a different location.</p>
  
  <p>This is how I have done this:</p>
  
  <pre class="lang-puppet prettyprint-override"><code>exec { "install_path_exists":
    command =&gt; "/bin/true",
    onlyif  =&gt; "/usr/bin/test -d ${install_path}",
    path    =&gt; ['/usr/bin','/usr/sbin','/bin','/sbin'],
  }
  file { "server_backup_dir" :
    ensure  =&gt; 'directory',
    path    =&gt; "${distribution_path}/backup/server",
    recurse =&gt; true,
    source  =&gt; "file:///${install_path}/repository/deployment/server",
    require =&gt; Exec["install_path_exists"],
  }
  </code></pre>
  
  <p>Exec checks if the directory exists, and returns true if so. The "server_backup_dir" file resource requires the "install_path_exists" exec to return true if the directory exists.</p>
  
  <p>When the directory does not exist, and "install_path_exists" returns false, "server_backup_dir" executes anyway, and produces the following error.</p>
  
  <blockquote>
    <p>Error: /Stage[main]/Is/File[server_backup_dir]: Could not evaluate:
    Could not retrieve information from environment production source(s)
    file:////usr/local/{project_location}/repository/deployment/server</p>
  </blockquote>
  
  <p>What is wrong with my approach, and how can I fix this? Thanks in advance.</p>