Ask Your Question

How can I use API to run "puppet agent -t" on the node

asked 2017-09-15 15:45:49 -0600

nick-cloudpassage gravatar image

Is there any way to do this via API? I have the certname of the node and need to use API to initiate the puppet run on the node.

edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted

answered 2017-09-16 05:46:15 -0600

Henrik Lindberg gravatar image

updated 2017-09-20 02:43:15 -0600

There is no such simple Ruby API (if that is what was asked). For that you would have to set things up like Puppet does for running the Application named Apply - it is designed to run from the command line so it will call exit, which makes it pretty useless as an API. Thus you would have to do the same things that it does in your code and that is very much not recommended as not everything it is doing is based on stable APIs.

For those reasons - it is far better to just "fork/exec" the command and use detailed exit codes to be able to react to the result of the agent run.

edit flag offensive delete link more

answered 2017-09-19 08:48:13 -0600

erichymowitz gravatar image

Look into ansible -- it is designed to remotely run software, and it has a built-in hook to sudo to root.

ansible all -i hostname, -bK -a "puppet agent -t --noop"

(the comma is required after the hostname)

edit flag offensive delete link more


there is also a 'puppet' playbook/module/type that you can use. It's pretty common (since puppet deprecated 'puppet kick') for people to use ansible as the puppet orchestration layer

DarylW gravatar imageDarylW ( 2017-09-19 11:25:55 -0600 )edit

answered 2017-09-16 01:19:22 -0600

stivesso gravatar image


Not sure about how to achieve this using API, but if the aim is to be able to trigger a puppet run remotely (and on more than one node), then I am suggesting to use Mcollective (coming with the Enterprise Version). I added below some example of how it is working (Command executed from PE Master as peadmin), there are many great examples on the official documentation.

Running Puppet (puppet agent -t) on a specific node (fqdn of the node in this example is:

$ mco puppet runonce -v -I

Running Puppet (puppet agent -t) on many nodes (filter by a regex matching all nodes with Xnode in their fqdn).

$ mco puppet runall 5 -v -S "fqdn=/Xnode/"
edit flag offensive delete link more


as a follow up, the author of mcollective has been working on a set of plugins to make it less painful to use...

DarylW gravatar imageDarylW ( 2017-09-19 11:27:17 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2017-09-15 15:45:49 -0600

Seen: 320 times

Last updated: Sep 20 '17