Skip to content

Instantly share code, notes, and snippets.

require 'r10k/puppetfile'
require 'gitlab'
GITLAB_TRUE = 1
GITLAB_FALSE = 0
# this is just to mirror what we had on the internetz internally
task :mirror do
gitlab_token = '<REDACTED>'
gitlab_host = 'gitlab.example.com'
@acidprime
acidprime / resource_print.rb
Last active March 15, 2017 17:36
Print aggregate resource lists in older versions of PuppetDB
#!/opt/puppet/bin/ruby
require 'net/http'
require 'uri'
require 'json'
def cputs(string)
puts "\033[1m#{string}\033[0m"
end
check_resource = ARGV[0]
@acidprime
acidprime / fact_yaml_print.rb
Last active March 14, 2017 14:34
Read puppet yamlcache and make tables from the facts
#!/usr/bin/env ruby
require 'puppet'
require 'terminal-table'
output = Hash.new
Factspath = ARGV[0]
FACTS = ['osfamily','lsbmajdistrelease','puppetversion','rubyversion','virtual','architecture','role','gpu','location']
#raise "Must pass facts directory as postional parameter 1" unless Dir.exists?(Factspath) or Factspath.nil?
@acidprime
acidprime / enable_jmx.rb
Last active January 4, 2017 23:41
A simple script to enable JMX listener in Puppet Enterprise.
#!/opt/puppetlabs/puppet/bin/ruby
require 'puppetclassify'
require 'puppet'
# Have puppet parse its config so we can call its settings
Puppet.initialize_settings
# Read classifier.yaml for split installation compatibility
def load_classifier_config
configfile = File.join Puppet.settings[:confdir], 'classifier.yaml'
require 'net/ldap'
require 'facter'
# This code is only ever loaded in newer versions of puppet and ruby
# https://github.com/puppetlabs/puppet-specifications/blob/master/language/func-api.md
Puppet::Functions.create_function(:get_ldap_group) do
dispatch :get_ldap_group do
param 'Variant[Array[String],String]', :groups
optional_param 'Variant[Array[String],String]', :attrs
optional_param 'Boolean', :single_attr
end
@acidprime
acidprime / current_license_usage.rb
Last active September 14, 2016 19:36
Check the current license count against puppetdb
#!/opt/puppetlabs/puppet/bin/ruby
require 'puppet'
require 'puppet/util/puppetdb'
require 'uri'
require 'json'
require 'yaml'
# Have puppet parse its config so we can call its settings
#!/opt/puppetlabs/puppet/bin/ruby
require 'rugged'
require 'octokit'
require 'yaml'
# needs refactoring for code manager
# https://github.com/puppetlabs/control-repo/blob/production/scripts/code_manager_config_version.rb
environmentpath = ARGV[0]
environment = ARGV[1]
#!/opt/puppetlabs/puppet/bin/ruby
require 'puppetclassify'
require 'getoptlong'
require 'puppet'
require 'hiera'
require 'facter'
require 'r10k/environment'
require 'net/ssh'
require 'net/scp'
require 'resolv'
#!/opt/puppetlabs/puppet/bin/ruby
require 'puppet'
require 'puppet/face'
require 'yaml'
all_users = Puppet::Face[:resource, '0.0.1'].search("user")
puts all_users.to_yaml
#!/opt/puppetlabs/puppet/bin/ruby
require 'net/http'
require 'json'
require 'yaml'
# Currently do not have this working with client side SSL, perhaps someone can help with that in the comments.
host = 'localhost'
port = '8080'
http = Net::HTTP.new(host, port)
resources_uri = '/pdb/query/v4/resources/User'
puts JSON.parse(http.get(resources_uri).body).to_yaml