This post is the next in a series of posts that shows how to integrate a complete production puppet environment with serf. In this post we learn how to use serf to fire off r10k updates on your compile masters. This takes the place of running mco r10k synchronize.

r10k Custom Serf Query

This post builds off the my last serf post SERF CUSTOM QUERIES, but this time we are going to add this functionality to the puppetserver(s).

Create the following directory structure on each of your compile masters where you have r10k running,

├── handlers
│   └── query-r10k

The code for the file is exactly the same as the last post:


if [ "$SERF_EVENT" = "user" ]; then
elif [ "$SERF_EVENT" = "query" ]; then

[ -f "$HANDLER" -a -x "$HANDLER" ] && exec "$HANDLER" || :

Custom r10k Query

Now we need to write our custom query script query-r10k. This will be triggered when serf receives a query called r10k.


/opt/ $>/dev/null $disown

echo "Starting r10k Update"

This calls in another process because we need to get a response back to serf within 15 seconds. Here is the code for runr10k:


/opt/puppetlabs/puppet/bin/r10k deploy environment -p -v

This will run r10k for us to deploy all environments.

Trigger r10k Update

Now that we have everything ready we can trigger r10k updates on all our compile masters with a single command:

# serf query r10k

This a basic example of what we can do with serf and r10k. We could update it by sending something in the serf payload to send a module name. The query-r10k script could pick this up and know to deploy/update a single module. Maybe that will be another post. That would be very useful if you are deploying application updates to a server(s) from your CI/CD solution like jenkins.

I hope you enjoyed this post. If it was helpful or if it was way off then please comment and let me know.

Tags: ,
%d bloggers like this: