You can try something like this:
file { 'bash_profile.local': ensure => present, source => ['puppet:///modules/local/bash_profile.local', '/dev/null'], path => '/home/vagrant/.bash_profile.local', before => Exec['clean-useless-file'], } exec { 'clean-useless-file': command => 'rm .bash_profile.local', onlyif => 'test -s .bash_profile.local', cwd => '/home/vagrant', path => '/bin:/usr/bin', }
If the administrator does not create a copy of ".bash_profile.local" available in "modules / local / bash_profile.local", the file resource will use the second source and then create an empty file. Then the "onlyif" test fails, and exec will delete the useless empty file.
Used in this way, this code can be a little cumbersome, but it is better than refusing to initialize. You can evaluate if an empty .bash_profile.local file can be saved in your case. I usually use a variant of this, with wget instead of rm, to get a new copy of the file from the Internet, if it was not already available as a source.
If you are using puppetmaster, keep in mind that you can use it to provide your own server representing two versions of the directory, depending on .bash_profile.local.
mfandrade
source share