Hi all! Please help me get understand my error: I have problems with onlyif/unless directives. Simple test work fine, for example: exec { "Update ovz templates": command => "wget -O /vz/template/cache/centos-5-i386- default.tar.gz http://install.local/ovz/templates/centos-5-i386-default.tar.gz && rm /vz/firsh_install.lock", path => "/usr/bin:/usr/sbin:/bin", onlyif => "test -f /vz/firsh_install.lock" } It''s exec run, and download teplate only if file /vz/ firsh_install.lock exist. I make custom script for running inside bash shell on puppet node, script return 0 or 1 When i try use it in puppet module, puppet run unless exec always, but onlyif exec never run. this exec does''nt work true: exec { "vecfg-applyset_${name}": command => "if [[ ( -d /vz/private/${veid} ) && ( -f /etc/ sysconfig/vz-scripts/${veid}.conf)]] ; then vzctl set ${veid} -- hostname ${vehostname} --ipadd ${veip} --nameserver ${vedns} --save; vzctl set ${veid} --applyconfig ${vetarif} --save; fi", path => ["/usr/bin", "/usr/sbin"], unless => "/usr/sbin/rc.test-parametrs-changed.sh ${veid} ${veip} $ {vetarif} ${vedns}", } file /usr/sbin/rc.test-parametrs-changed.sh work, in shell, fine (return 0 or 1): ===========================cat /usr/sbin/rc.test-parametrs- changed.sh #!/bin/ bash #Check VE settings for Puppet. Returned "1", if settings changed, else return 0 #Get variables VEID=$2 #also, $VEIP variable is variable of on/off status of conainer VEIP=$3 VETARIF=$4 VEDNS=$5 PATHVE="/vz/private/"$VEID PATHVECONF="/etc/vz/conf/"$VEID".conf" check_settings() { if [[ ( $(grep $VEIP $PATHVECONF 1>/dev/null 2>&1; echo $?) -eq 0) && ( $(grep $VETARIF $PATHVECONF 1>/dev/null 2>&1; echo $?) -eq 0 ) && ( $ (grep $VEDNS $PATHVECONF 1>/dev/null 2>&1; echo $? ) -eq 0 ) ]]; then exit 0; else exit 1; fi } check_status() { if [[ ( $(grep $VEIP $PATHVECONF 1>/dev/null 2>&1; echo $?) -eq 0 ) ]]; then exit 0; else exit 1; fi } case "$1" in check_settings) check_settings ;; check_status) check_status ;; *) echo $"Usage: $0 {check_settings|check_status}" exit 0 esac -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
jcbollinger
2009-Dec-14 17:13 UTC
[Puppet Users] Re: problems with onlyif/unless directives
On Dec 13, 1:20 pm, sHaggY_caT <galia....@gmail.com> wrote:> Please help me get understand my error:The debug output from trying to run these would probably help with that, but I''ll see whether I can provide at least a little insight anyway.> I have problems with onlyif/unless directives. Simple test work fine,[...]> I make custom script for running inside bash shell on puppet node, > script return 0 or 1 > > When i try use it in puppet module, puppet run unless exec always, but > onlyif exec never run.> this exec does''nt work true: > > exec { "vecfg-applyset_${name}": > command => "if [[ ( -d /vz/private/${veid} ) && ( -f /etc/ > sysconfig/vz-scripts/${veid}.conf)]] ; then vzctl set ${veid} -- > hostname ${vehostname} --ipadd ${veip} --nameserver ${vedns} --save; > vzctl set ${veid} --applyconfig ${vetarif} --save; fi", > path => ["/usr/bin", "/usr/sbin"], > unless => "/usr/sbin/rc.test-parametrs-changed.sh ${veid} ${veip} $ > {vetarif} ${vedns}", > } > > file /usr/sbin/rc.test-parametrs-changed.sh work, in shell, fine > (return 0 or 1):As far as I know, Exec executes its command(s) directly, not via a shell, so I would be surprised if that did what you expect, independent of the "unless". That is, "if" is a keyword in the sh language, not an executable program (not on any system I''m familiar with, anyway), so I would expect that Exec to fail every time it runs. For debugging your manifests, you could try using unless => "/bin/true" or unless => "/bin/false" to take that test script out of the picture. Speaking of the test script, are you sure your nodes are getting and using the correct version? You can have the puppetmaster distribute it, but you may need to set up a require for it to make sure its downloaded first. (It''s not clear from the docs whether Puppet will autorequire it from the "unless" parameter.) You''ll also want to make sure its ownership and permissions are set appropriately. John -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
sHaggY_caT
2009-Dec-15 11:12 UTC
[Puppet Users] Re: problems with onlyif/unless directives
Hi John, Thank you for answer.> For debugging your manifests, you could try using > > unless => "/bin/true" > > or > > unless => "/bin/false" > > to take that test script out of the picture.Script, in "command" work fine.> Speaking of the test script, are you sure your nodes are getting and > using the correct version?It''s use one version, without differents of number: [shaggycat@puppet ~]$ rpm -qa | grep puppet puppet-server-0.24.8-1.el5.1 puppet-0.24.8-1.el5.1 [shaggycat@puppet ~]$ [root@vz-test conf]# rpm -qa | grep puppet puppet-0.24.8-1.el5.1 [root@vz-test conf]#> As far as I know, Exec executes its command(s) directly, not via a > shell, so I would be surprised if that did what you expect, > independent of the "unless". That is, "if" is a keyword in the sh > language, not an executable program (not on any system I''m familiar > with, anyway), so I would expect that Exec to fail every time it runs.OK, i think you true. Do you have means, how use bash script inside "onlyif"/"unless"? I try use script in command line: [root@vz-test conf]# test "/usr/sbin/rc.test-parametrs-changed.sh check_settings 301 10.0.5.31 yes vps256M 10.0.5.52" [root@vz-test conf]# echo $? 0 [root@vz-test conf]# /usr/sbin/rc.test-parametrs-changed.sh check_settings 301 10.0.5.31 yes vps256M 10.0.5.52 [root@vz-test conf]# echo $? 1 [root@vz-test conf]# but, bash exec(system command) return 0: [root@vz-test conf]# bash /usr/sbin/rc.test-parametrs-changed.sh check_settings 301 10.0.5.31 yes vps756M 10.0.5.52 [root@vz-test conf]# echo $? 0 [root@vz-test conf]# but "unless" inside puppet exec run exec: exec { "vecfg-applyset_${name}": command => "if [[ ( -d /vz/private/${veid} ) && ( -f /etc/ sysconfig/vz-scripts/${veid}.conf) && \ ( $(/usr/sbin/rc.test-parametrs-changed.sh check_settings ${veid} ${veip} ${vetarif} ${vedns} ; echo $?) -eq 1)]] ; \ then vzctl set ${veid} --hostname ${vehostname} --ipadd ${veip} --nameserver ${vedns} --save; \ vzctl set ${veid} --applyconfig ${vetarif} --save; fi", path => ["/usr/bin", "/usr/sbin"], unless => "bash /usr/sbin/rc.test-parametrs-changed.sh check_settings ${veid} ${veip} ${vetarif} ${vedns}", } If/else inside "command" works, as i test (i use if/else inside command, becouse unless/onlyif does''nt work for me): [root@vz-test conf]# cat ~/tmp_2 | grep -v _off Dec 15 13:41:05 vz-test puppetd[23387]: Starting catalog run Dec 15 13:41:06 vz-test puppetd[23387]: (//Node[vz-test.local]/ Mod_class_ovzconfigs::Mod_def_veadm[customer2.vps.local]/Exec[vecfg- applyset_customer2.vps.local]/returns) executed successfully Dec 15 13:41:16 vz-test puppetd[23387]: (//Node[vz-test.local]/ Mod_class_ovzconfigs::Mod_def_ovzbackup[ovzserver_backup]/Cron [incremental_backup]/weekday) defined ''weekday'' as ''*'' Dec 15 13:43:07 vz-test puppetd[23387]: (//Node[vz-test.local]/ Mod_class_ovzconfigs::Mod_def_veadm[customer1.vps.local]/Exec[vecfg- applyset_customer1.vps.local]/returns) executed successfully Dec 15 13:43:14 vz-test puppetd[23387]: (//Node[vz-test.local]/ Mod_class_ovzconfigs::Mod_def_veadm[customer4.vps.local]/Exec[vecfg- applyset_customer4.vps.local]/returns) executed successfully Dec 15 13:43:29 vz-test puppetd[23387]: Finished catalog run in 143.67 seconds> You can have the puppetmaster distribute > it, but you may need to set up a require for it to make sure its > downloaded first. (It''s not clear from the docs whether Puppet will > autorequire it from the "unless" parameter.) You''ll also want to make > sure its ownership and permissions are set appropriately. > > John-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
sHaggY_caT
2009-Dec-15 16:17 UTC
[Puppet Users] Re: problems with onlyif/unless directives
I think, problems was resolved: Exec with this "onlyif": onlyif => "test `/root/test-new.sh ${veid} ${vetarif}` = 0 " Run only if $veid=302: Dec 15 19:12:19 vz-test puppetd[16426]: Starting catalog run Dec 15 19:12:45 vz-test puppetd[16426]: (//Node[vz-test.local]/ Mod_class_ovzconfigs::Mod_def_ovzbackup[ovzserver_backup]/Cron [incremental_backup]/weekday) defined ''weekday'' as ''*'' Dec 15 19:12:46 vz-test puppetd[16426]: (//Node[vz-test.local]/ Mod_class_ovzconfigs::Mod_def_veadm[customer2.vps.local]/Exec[vecfg- applyset_customer2.vps.local]/returns) executed successfully Dec 15 19:12:46 vz-test puppetd[16426]: Finished catalog run in 27.27 seconds onlyif => "test `/root/test-new.sh ${veid} ${vetarif}` = 0 " [root@vz-test conf]# cat /root/test-new.sh #!/bin/bash if [[ $1 = 302 ]] then echo 0 else echo 1 fi Thank you for answer. For another puppet users, who find this topic: try to use binary file test for test with your custom scripts :)) On 15 дек, 11:12, sHaggY_caT <galia....@gmail.com> wrote:> Hi John, > > Thank you for answer. > > > For debugging your manifests, you could try using > > > unless => "/bin/true" > > > or > > > unless => "/bin/false" > > > to take that test script out of the picture. > > Script, in "command" work fine. > > > Speaking of the test script, are you sure your nodes are getting and > > using the correct version? > > It''s use one version, without differents of number: > > [shaggycat@puppet ~]$ rpm -qa | grep puppet > puppet-server-0.24.8-1.el5.1 > puppet-0.24.8-1.el5.1 > [shaggycat@puppet ~]$ > > [root@vz-test conf]# rpm -qa | grep puppet > puppet-0.24.8-1.el5.1 > [root@vz-test conf]# > > > As far as I know, Exec executes its command(s) directly, not via a > > shell, so I would be surprised if that did what you expect, > > independent of the "unless". That is, "if" is a keyword in the sh > > language, not an executable program (not on any system I''m familiar > > with, anyway), so I would expect that Exec to fail every time it runs. > > OK, i think you true. Do you have means, how use bash script inside > "onlyif"/"unless"? > I try use script in command line: > > [root@vz-test conf]# test "/usr/sbin/rc.test-parametrs-changed.sh > check_settings 301 10.0.5.31 yes vps256M 10.0.5.52" > [root@vz-test conf]# echo $? > 0 > [root@vz-test conf]# /usr/sbin/rc.test-parametrs-changed.sh > check_settings 301 10.0.5.31 yes vps256M 10.0.5.52 > [root@vz-test conf]# echo $? > 1 > [root@vz-test conf]# > > but, bash exec(system command) return 0: > > [root@vz-test conf]# bash /usr/sbin/rc.test-parametrs-changed.sh > check_settings 301 10.0.5.31 yes vps756M 10.0.5.52 > [root@vz-test conf]# echo $? > 0 > [root@vz-test conf]# > > but "unless" inside puppet exec run exec: > > exec { "vecfg-applyset_${name}": > command => "if [[ ( -d /vz/private/${veid} ) && ( -f /etc/ > sysconfig/vz-scripts/${veid}.conf) && \ > ( $(/usr/sbin/rc.test-parametrs-changed.sh check_settings ${veid} > ${veip} ${vetarif} ${vedns} ; echo $?) -eq 1)]] ; \ > then vzctl set ${veid} --hostname ${vehostname} --ipadd ${veip} > --nameserver ${vedns} --save; \ > vzctl set ${veid} --applyconfig ${vetarif} --save; fi", > path => ["/usr/bin", "/usr/sbin"], > unless => "bash /usr/sbin/rc.test-parametrs-changed.sh > check_settings ${veid} ${veip} ${vetarif} ${vedns}", > } > > If/else inside "command" works, as i test (i use if/else inside > command, becouse unless/onlyif does''nt work for me): > > [root@vz-test conf]# cat ~/tmp_2 | grep -v _off > Dec 15 13:41:05 vz-test puppetd[23387]: Starting catalog run > Dec 15 13:41:06 vz-test puppetd[23387]: (//Node[vz-test.local]/ > Mod_class_ovzconfigs::Mod_def_veadm[customer2.vps.local]/Exec[vecfg- > applyset_customer2.vps.local]/returns) executed successfully > Dec 15 13:41:16 vz-test puppetd[23387]: (//Node[vz-test.local]/ > Mod_class_ovzconfigs::Mod_def_ovzbackup[ovzserver_backup]/Cron > [incremental_backup]/weekday) defined ''weekday'' as ''*'' > Dec 15 13:43:07 vz-test puppetd[23387]: (//Node[vz-test.local]/ > Mod_class_ovzconfigs::Mod_def_veadm[customer1.vps.local]/Exec[vecfg- > applyset_customer1.vps.local]/returns) executed successfully > Dec 15 13:43:14 vz-test puppetd[23387]: (//Node[vz-test.local]/ > Mod_class_ovzconfigs::Mod_def_veadm[customer4.vps.local]/Exec[vecfg- > applyset_customer4.vps.local]/returns) executed successfully > Dec 15 13:43:29 vz-test puppetd[23387]: Finished catalog run in 143.67 > seconds > > > > > You can have the puppetmaster distribute > > it, but you may need to set up a require for it to make sure its > > downloaded first. (It''s not clear from the docs whether Puppet will > > autorequire it from the "unless" parameter.) You''ll also want to make > > sure its ownership and permissions are set appropriately. > > > John-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.