Skip to content

Instantly share code, notes, and snippets.

View binford2k's full-sized avatar

Ben Ford binford2k

View GitHub Profile
# BLOWS UP
require 'socket'
Puppet::Parser::Functions.newfunction(:mastername, :type => :rvalue ) do
Socket.gethostname.chomp
end
[root@classroom test]# puppet apply -e 'notice(mastername())'
Error: wrong number of arguments (1 for 0) at line 1 on node classroom.puppetlabs.vm
Wrapped exception:
// This is a quick example to show how something like ruby blocks might be implemented in another language
// psuedo code follows, don't get hung up on syntax
class Array {
std::vector<int> array;
Array (std::vector in) {
self.array = in;
}
#!/bin/sh
# hackyfix ze puppets to run on mavericks
cd /usr/lib/ruby/site_ruby/2.0.0
for i in "facter hiera hiera_puppet.rb puppet.rb puppetx.rb facter.rb hiera.rb puppet puppetx semver.rb"
do
sudo ln -s ../1.8/${i} ${i}
done
#!/usr/bin/env ruby
require 'yaml'
require 'syslog'
require 'net/https'
FOREMAN = 'http://foreman.server.org'
MASTER = 'puppet.master.org'
RAKEAPI = "ssh #{MASTER} /opt/puppet/bin/rake -f /opt/puppet/share/puppet-dashboard/Rakefile RAILS_ENV=production node:add['%name',,'%classes']"
GITROOT = '/var/repos'
#! /usr/bin/env ruby
require 'rubygems'
require 'sinatra/base'
require 'webrick'
#require 'webrick/https'
#require 'openssl'
require 'resolv'
require 'json'
#!/bin/bash
#
# webhooks Manage webhooks service
#
# chkconfig: 2345 55 25
# description: Stupidsimple webhooks implementation.
#
# This is a pretty cruddy init script.
# source function library
# The problem is that an RPM package may have a dependency on the asterisk-11-repo RPM
# package itself. If you install the other package, it will also pull in the RPM package.
# That's a bit icky, to be sure, but it won't actually *break* anything.
#
# The repo package would be installed, which would drop in a .repo file, but only do
# that ONE time. The yumrepo provider would then overwrite it with the actual contents
# as defined in your manifest and then maintain those properties.
#
# This is exactly how it works when you install a package with sample configuration files
# and then manage the real configuration files with Puppet.
#! /opt/puppet/bin/ruby
require 'json'
raise "Run this script with a node name that has had a catalog compiled on this master" unless ARGV.size == 1
catalog = JSON.parse(File.read("/var/opt/lib/pe-puppet/client_data/catalog/#{ARGV[0]}.json"))
puts " Class count: #{catalog['data']['resources'].select { |r| r['type'] == 'Class' }.size}"
puts "Resource count: #{catalog['data']['resources'].reject { |r| r['type'] == 'Class' }.size}"
#! /usr/bin/env ruby
require 'augeas'
Augeas::open do |aug|
puts aug.get('/files/etc/krb5.conf/libdefaults/default_realm')
end
@binford2k
binford2k / inheritance.pp
Last active January 3, 2016 03:39
Demonstrate composition instead of inheritance
################### don't do this ###################
node default {
include something
include something else
}
node 'boo' inherits default {
include a third thing
}