I am trying to use Puppet to modify file content, but if file doesn't exist, I will skip and do nothing. However, i found the dependency checking just work in the first iteration, but after that, it seems not function. Here is my puppet manifests:
class tibco::hawk_gc_tuning {
$domain_array = split($domain_list, '\n')
$hawkgc = hiera('hawk_gc_arg','xxxxxx')
$domain_array.each |$tibcodomain| {
notify { "Now in : ${tibcodomain} ": }
exec {"check_presence_${tibcodomain}":
path => "/usr/bin:/usr/sbin:/bin",
command => 'true',
onlyif => "test -e /home/tibco/tra/domain/${tibcodomain}/hawkagent_${tibcodomain}.tra"
}
file_line { "change $tibcodomain hawk agent gc arg comment":
require => Exec["check_presence_${tibcodomain}"],
path => "/home/tibco/tra/domain/${tibcodomain}/hawkagent_${tibcodomain}.tra",
line => '# tuning for hawkagent',
match => '^# tuning for hawkagent',
}->
file_line { "change $tibcodomain hawk agent gc arg":
path => "/home/tibco/tra/domain/${tibcodomain}/hawkagent_${tibcodomain}.tra",
line => "${hawkgc}",
match => '^java.extended.properties=-XX\\\\:MaxPermSize\\\\=.*',
}
}
}
Below is the output from my code:
Notice: Now in : A Notice: /Stage[main]/Tibco::Hawk_gc_tuning/Notify[Now in : A ]/message: defined 'message' as 'Now in : A ' Notice: /Stage[main]/Tibco::Hawk_gc_tuning/Exec[check_presence_A]/returns: executed successfully Notice: Now in : B Notice: /Stage[main]/Tibco::Hawk_gc_tuning/Notify[Now in : B ]/message: defined 'message' as 'Now in : B ' Error: /Stage[main]/Tibco::Hawk_gc_tuning/File_line[change B hawk agent gc arg comment]: Could not evaluate: No such file or directory - /home/tibco/tra/domain/B/hawkagent_B.tra Notice: /Stage[main]/Tibco::Hawk_gc_tuning/File_line[change B hawk agent gc arg]: Dependency File_line[change B hawk agent gc arg comment] has failures: true Warning: /Stage[main]/Tibco::Hawk_gc_tuning/File_line[change B hawk agent gc arg]: Skipping because of failed dependencies Notice: Now in : C Notice: /Stage[main]/Tibco::Hawk_gc_tuning/Notify[Now in : C ]/message: defined 'message' as 'Now in : C ' Error: /Stage[main]/Tibco::Hawk_gc_tuning/File_line[change C hawk agent gc arg comment]: Could not evaluate: No such file or directory - /home/tibco/tra/domain/C/hawkagent_C.tra Notice: /Stage[main]/Tibco::Hawk_gc_tuning/File_line[change C hawk agent gc arg]: Dependency File_line[change C hawk agent gc arg comment] has failures: true Warning: /Stage[main]/Tibco::Hawk_gc_tuning/File_line[change C hawk agent gc arg]: Skipping because of failed dependencies Notice: Finished catalog run in 1.06 seconds
As you can see above, both A, B, C are not exists, but only the first one, A, gives correct result and skip the file_line resources. Could someone give me some hints on the problem?