Last active
December 9, 2019 21:02
-
-
Save ripienaar/c984d1ca6d4d5ea1b13e359b9ad9a19f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Run puppet, unsplayed in noop mode, on all machines for customer acme | |
// in batches of 10 at a time with a 30 second sleep between batches | |
// against a specific puppet server | |
// | |
// This is all you need, there's no boilerplate removed other than imports | |
// this does: | |
// | |
// - connect to your choria network | |
// - handles all the security including pkcs11 (yubikeys) | |
// - discovery etc - though discovery is pluggable even here | |
// - preserves types in and out of ruby (or any other language) converting to equivelant go types with fall back to interface{} for unknown | |
// - full usual input validation before hitting the network | |
// - all the comms, scaling etc, this will comfortably work on 50k nodes (your puppet server not so much) | |
// - cleans up when its done with it | |
// - threadsafe | |
// | |
// CLI equivelant: | |
// | |
// $ choria rpc puppet runonce -W customer=acme --batch 10 --batch-sleeep 30 splay=true noop=true server=other.example.net | |
// | |
func runonce() error { | |
pc := puppetclient.Must() | |
res, err := pc.OptionFactFilter("customer=acme").OptionInBatches(10, 30).Runonce().Noop(true).Splay(false).Server("other.example.net").Do(context.Background()) | |
if err != nil { | |
return err | |
} | |
res.EachOutput(func(r *puppetclient.RunonceOutput) { | |
if r.ResultDetails().OK() { | |
fmt.Printf("OK: %-40s: %v\n", r.ResultDetails().Sender(), r.Status() | |
} else { | |
fmt.Printf("!!: %-40s: message: %s\n", r.ResultDetails().Sender(), r.ResultDetails().StatusMessage()) | |
} | |
}) | |
return nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment