简体   繁体   中英

puppet exec command issue

Below is my puppet code ,It is killing the process in agent but showing the error code

exec { "restart_process":
    command => "ps -ef | grep nrpe | grep -v pts/1 | /bin/awk '{print $2}' | xargs kill -9",
    path => ['/usr/bin', '/sbin', '/bin', '/usr/sbin'],
    subscribe => File["/root/Backup/deploy"],
    refreshonly => true,
}

Error code:

Info: Computing checksum on file /root/Backup/deploy/nrpe.sh
Info: /Stage[main]/Myfile/File[/root/Backup/deploy/nrpe.sh]: Filebucketed /root/Backup/deploy/nrpe.sh to puppet with sum   136c6013774f5dfb84943718a70b36e0
Notice: /Stage[main]/Myfile/File[/root/Backup/deploy/nrpe.sh]/content: content 
changed '{md5}136c6013774f5dfb84943718a70b36e0' to '{md5}c4fc9099405a108923ad18f7e2db13c8'
Info: /root/Backup/deploy: Scheduling refresh of Exec[restart_process]
Error: /Stage[main]/Myfile/Exec[restart_process]: Failed to call refresh: ps -ef | grep nrpe | grep -v pts/1 | /bin/awk '{print }' | xargs kill -9 returned  instead of one of [0]
Error: /Stage[main]/Myfile/Exec[restart_process]: ps -ef | grep nrpe | grep -v pts/1 | /bin/awk '{print }' | xargs kill -9 returned  instead of one of [0]
Notice: Finished catalog run in 1.56 seconds

Can any body help me

@maxd is right that you need to escape the $ in the command when you specify it to Puppet. This is because Puppet performs its own variable interpolation on quotation-mark-quoted strings, and this will replace the $2 with the relevant replacement string -- probably an empty string -- before your command even reaches the catalog, and long before any attempt is made to run it.

I don't think that's your fundamental problem, however. Your command is a shell pipeline, but the default Exec provider for your system is almost certainly posix , and that provider will not do what you want with the command string you provided. You probably want to add

provider => 'shell'

to your resource, to have Puppet use the shell to execute it instead of trying to execute it directly as a (single) command.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM