Created
January 24, 2018 19:08
-
-
Save WhatsARanjit/79d771adb6b88743f76c4e1778b54c8e to your computer and use it in GitHub Desktop.
What groups am I in?
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
#!/usr/bin/env ruby | |
require 'puppet' | |
require 'json' | |
Puppet.initialize_settings | |
require File.join(Puppet['plugindest'], 'puppet', 'util', 'nc_https.rb') | |
nodename = ARGV[0] | |
raise ArgumentError, 'Please supply a nodename' unless nodename | |
classifier = Puppet::Util::Nc_https.new | |
raw = classifier.get_classified(nodename) | |
# Using T/P to collect group instances | |
Puppet::Type.type(:node_group) | |
Puppet::Type::Node_group::ProviderHttps.instances | |
# Translating IDs to names | |
groups = raw['groups'].collect do |group| | |
gindex = Puppet::Type::Node_group::ProviderHttps.get_name_index_from_id(group) | |
$ngs[gindex]['name'] | |
end | |
puts groups |
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
[root@puppet ~]# ./groups_lookup.rb $(puppet config print certname) | |
All Nodes | |
Production environment | |
PE Orchestrator | |
PE Certificate Authority | |
PE PuppetDB | |
PE Master | |
PE Console | |
PE ActiveMQ Broker |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment