On Wednesday, February 12, 2014 9:14:19 AM UTC-6, Andreas Dvorak wrote: > > Dear all, > > ich habe a defined class, that is called two times in on class but only > the first call is executed. > baader::replace {'access notConfigGroup' is done, but not baader::replace > {'com2sec notConfigUser': > And baader::replace {'view all included': is done. > Can somebody please explain the reason and how can I solve this? >
Your definition has a suspicious bit that is probably a cut & paste error. > > define baader::replace($file, $old, $new, $ensure = 'replace') { > $grep='/bin/grep' > $sed='/bin/sed' > > case $ensure { > default : { err ( "unknown ensure value ${ensure}" ) } > replace : { > exec { "${sed} -i -e's/${old}/${new}/' '${file}'": > unless => "${grep} -qFx '${old}' '${file}'", > Consider the 'unless' parameters here ^ > onlyif => "/usr/bin/test -f '${file}'", > } > } > insert_after : { > exec { "${sed} -i -e's/${old}/&\\n${new}/' '${file}'": > unless => "${grep} -qFx '${old}' '${file}'", > and here ^ > onlyif => "/usr/bin/test -f '${file}'", > } > } > } > } > > When your defined type is operating in 'replace' mode, the 'unless' parameter to the Exec tells it to do nothing if the string to replace appears as a complete line of the target file. It is possible that you really do mean that -- that is, you only want to perform the replacement if the 'old' string is part of a larger line -- but I'm guessing that it's just copied from the 'unless' parameter in the other alternative. If the objective is instead to avoid running sed when it wouldn't have any effect, then you want something more like this: onlyif => "/usr/bin/test -f '${file}' && ${grep} -qF '${old}' '${file}'" It is possible that you will need also to declare provider => 'shell' to make it work. You can verify that the overall definition is being applied in each case by adding a Notify resource to it, but I am confident that you will find it indeed is being applied. John -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/44259c7e-0438-4d79-8d88-6750b9ad8b7c%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.