Search code examples
puppet

Copying a file only once in puppet


I am new to puppet, I am trying to copy a file to remote server for installation of a package, This file would get deleted a few minutes after installation. Is there a way to copy this file only once.? like the example below.

class absent_file {

  file { '/tmp/hello-file':
    ensure  => 'present',
    replace => 'no',
    content => "From Puppet\n",
    mode    => '0644',
    once    => true
  }

} 

Solution

  • So, I have figured out how to do it. Instead of using the file module, I ended up using command and touching another which would not get deleted along with installation process. The key can be deleted but the somefile.txt would be still present and the process would become idempotent.

    exec {'add key':
      command => "echo 'SharedKeyfile' > /key/location && touch /key/location/somefile.txt'",
      onlyif  => "test ! -f /key/location/somefile.txt",    
    }