Using Serf with Puppet R10k Howto

In this post I give you a  HashiCorp Serf with Puppet R10k HOWTO that will fire off r10k updates on your compile masters.

This post is the next in a series of posts that shows how to integrate a complete production puppet environment with Serf.  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.

Click here for more great articles from AdminTome Blog.


I hope you have enjoyed this article, if so please leave a comment below.  For more articles, please signup for the AdminTome Blog below.  Also please feel free to share the article to your friends using the buttons to the left.  Thanks again for reading this post.

Signup for the AdminTome Blog Newsletter

Get weekly updates from AdminTome Blog including the latest articles and special content only for subscribers.

privacy We value your privacy and would never spam you

Tags: ,
%d bloggers like this: