Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Clean up/purge unresponsive nodes that count against your license count. Puppet Enterprise 2016.1 2016.2 2016.
require "httparty"
# Unresponsive node cleanup for Puppet Enterprise 2016.2
# When our system scales down, we often have many unresponsive nodes. These
# nodes count towards our overall license count. Future scaling events will
# keep stacking these unused licenses. This is a simple method to purge the
# unresponsive nodes.
# This script can be run periodically on the puppet master to clean up
# unresponsive nodes.
# To access the puppet api from the command line, you'll need to generate an
# access token. In puppet console, create a user who is part of the admin
# group. Follow this to create a token.
# $ puppet-access login --lifetime 0
# Location for Ubuntu 14.04.5 LTS
token = `cat /home/ubuntu/.puppetlabs/token`
# query used to determine unresponive nodes (nodes that haven't reported in
# over an hour. using 2 hours.)
query = ["<", "report_timestamp", ( - 7200).utc.iso8601].to_json
url = "http://localhost:8080/pdb/query/v4/nodes?query=#{query}"
response = HTTParty.get(url, headers: {"X-Authentication" => token}, verify: false)
# unresponsvie node certs
certs = response.collect{|x| x["certname"]}
puts "purging old node certs..."
result = false
certs.each do |cert|
# returns true if successfully executed
result = system( "sudo puppet node purge #{cert}")
# if we purged nodes, we'll need to run puppet agent and restart puppet server
if result
puts "run puppet agent..."
system( "sudo puppet agent -t" )
puts "restart puppet server...(this may take a few minutes)"
system( "sudo service pe-puppetserver restart" )
puts "no unresponsive nodes"
puts "done!"

This comment has been minimized.

Copy link
Owner Author

commented Feb 7, 2017

An older version of this, for earlier versions of Puppet 3, can be found here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.