Created
January 26, 2018 00:36
-
-
Save natemccurdy/e5237015ffc63f67dc44ccc19ebd380a to your computer and use it in GitHub Desktop.
Ruby script to get the names of compile masters from 'puppet infra'
This file contains 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
#!/opt/puppetlabs/puppet/bin/ruby | |
# This script returns an array of compile masters in JSON based on the output of `puppet infra status`. | |
# Useful for feeding into a task or a plan. | |
require 'facter' | |
require 'json' | |
require 'open3' | |
def puppet_infra_status | |
stdout, _stderr, _status = Open3.capture3('/opt/puppetlabs/puppet/bin/puppet infra status --format json') | |
stdout.strip | |
end | |
services = JSON.parse(puppet_infra_status) | |
compile_masters = [] | |
services.each do |service| | |
compile_masters << service['server'] if service['service'] == 'pe-master' && service['server'] != Facter.value('fqdn') | |
end | |
puts compile_masters.to_json |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment