Menu

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,

/etc/serf
├── handlers
│   └── query-r10k
└── handler.sh

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

#!/bin/sh
HANDLER_DIR="/etc/serf/handlers"

if [ "$SERF_EVENT" = "user" ]; then
    EVENT="user-$SERF_USER_EVENT"
elif [ "$SERF_EVENT" = "query" ]; then
    EVENT="query-$SERF_QUERY_NAME"
else
    EVENT=$SERF_EVENT
fi

HANDLER="$HANDLER_DIR/$EVENT"
[ -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.

#!/bin/bash                                                                                                                                                               

/opt/runr10k.sh $>/dev/null $disown

echo "Starting r10k Update"

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

#!/bin/bash                                                                                                                                                               

/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.

Conclusion

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: