Sebastian Hempel bio photo

Sebastian Hempel

Software Crafter, Clean-Code-Developer, JEE Professional, Puppet-Master, OpenSource Fanboy, Alfisti

Email Twitter XING Instagram Github

When puppet replaces an already existing file, it stores the old content into the clientbucket and returns the hash value of this version. To restore a file from the clientbucket you normaly use the puppet clientbucket command with this hash on the node. But it’s also possible to define a “special” file resource, to restore the content form the clientbucket to a newly defined file.

Let me explain this “feature” with a small example. On the last puppet run the content of the file /etc/fstab was stored into the clientbucket with the hash value 77461bf606abbbd17f88a806fc21562b.

You can now define a file resource to restore the content of this stored file into a new file /tmp/old-fstab.

file { '/tmp/old-fstab':
  ensure  => file,
  content => "{md5}77461bf606abbbd17f88a806fc21562b",

Place this resource in an module or place the definition directly into the node resource.

On the next puppet run the defined file /tmp/old-fstab will be created. The “magic” content ensures, that the newly created file contains the content of the file in the clientbucket with the given hash value.

I don’t know if this is a bug or a feature. I couldn’t find any “offical” documentation of this behaviour. But this method works fine in the puppet versions 2.6, 2.7 and 3.3.