I would like to add a functionality in the Puppet manifest to apply one configuration if another file exists, if doesn't exists should apply a different configuration. I have tried this part of code:
exec { "chk_file_exist":
path => ["/usr/bin","/usr/sbin", "/bin"],
onlyif => "test -f ${file} && echo 0",
before => File['/etc/systemd/system/config1.service'],
}
exec { "chk_file_doesnt_exist":
path => ["/usr/bin","/usr/sbin", "/bin"],
onlyif => "test ! -f ${file} && echo 0",
refreshonly => true,
before => File['/etc/systemd/system/config2.service'],
}
file { '/etc/systemd/system/config1.service':
content => template('module/service/config1.service'),
require => Exec["chk_file_exist"],
}
file { '/etc/systemd/system/config2.service':
content => template('module/service/config2.service'),
require => Exec["chk_file_doesnt_exist"],
}
It creates just one file, but it throws an error:
Error: Could not find command 'chk_file_exist'
Error: /Stage[main]/mymodule::service/Exec[chk_file_exist]/returns: change from 'notrun' to ['0'] failed: Could not find command 'chk_file_exist' (corrective)
How I can avoid this error?
Thank you
fileresource given the file's existence. Give it a search and you will find the assistance you are looking for. - Matt SchuchardExecresources and resource relationships do not serve this objective. - John Bollinger