Skip to content

Instantly share code, notes, and snippets.

@WhatsARanjit
Created January 24, 2018 19:08
Show Gist options
  • Save WhatsARanjit/79d771adb6b88743f76c4e1778b54c8e to your computer and use it in GitHub Desktop.
Save WhatsARanjit/79d771adb6b88743f76c4e1778b54c8e to your computer and use it in GitHub Desktop.
What groups am I in?
#!/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
[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