A collection of task oriented solutions in Puppet


Only add a file if it's absent.


You only want puppet to add a file if the file isn't already present. Once it's added, or if it's already there, you want to leave it alone.


class absent_file {

  file { '/tmp/hello-file':
    ensure  => 'present',
    replace => 'no', # this is the important property
    content => "From Puppet\n",
    mode    => '0644',



Adding the replace property with the value of 'no' (or the uglier 'false') to a file will stop puppet managing its content if the file already exists. If it's not already present then the file will be created as per the file types parameters and then left alone - even if its content changes on either the puppet master or client side.

In general this isn't the best approach as all configuration should be under centralised management. Having local changes that can drift over time will cause pain in the long run and make your systems baseline configuration harder to predict.

It's worth noting that the file type will still maintain permissions and other such file properties if they change on the client. Even with replace set to 'no'.