Skip to content

Instantly share code, notes, and snippets.

@ripienaar
Last active February 20, 2018 08:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ripienaar/b57bcd5081e2de73d438f4e220d333df to your computer and use it in GitHub Desktop.
Save ripienaar/b57bcd5081e2de73d438f4e220d333df to your computer and use it in GitHub Desktop.
# playbook to find all puppet servers via PQL discovery
# disable puppet on them and wait for them to idle
# up to 200 seconds, if any fail to idle by then
# an error is raised
#
# this is run via:
#
# mco playbook run acme::test --modulepath /path/to/modules
#
plan acme::disable_and_wait {
$r = acme::puppet::disable_and_wait(acme::puppet::nodes())
notice(sprintf("%d nodes have been disabled and completed their catalogs", $r.count))
}
# Disables Puppet on given nodes
#
# @param nodes which nodes to act on
function acme::puppet::disable (
Choria::Nodes $nodes
) >> Choria::TaskResults {
choria::task(
"action" => "puppet.disable",
"nodes" => $nodes,
"fail_ok" => true,
"silent" => true
)
}
# Disables Puppet on given nodes and wait for it to complete any in-progress catalog applies
#
# @param nodes which nodes to act on
# @param wait how long to wait for puppet nodes to idle, check will happen 10 times
function acme::puppet::disable_and_wait (
Choria::Nodes $nodes,
Integer $wait = 200
) >> Choria::TaskResults {
acme::puppet::disable($nodes)
choria::task(
"action" => "puppet.status",
"nodes" => $nodes,
"assert" => "idling=true",
"tries" => 10,
"try_sleep" => $wait / 10,
"silent" => true
)
}
# Discovers all nodes running the Puppet agent
#
# @param method the discovery method to use
function acme::puppet::nodes (
String $method = "choria"
) >> Choria::Nodes {
choria::discover(
discovery_method => $method,
agents => ["puppet"],
uses => {
puppet => "> 1.0.0"
}
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment