Skip to content

Instantly share code, notes, and snippets.

View binford2k's full-sized avatar

Ben Ford binford2k

View GitHub Profile
@binford2k
binford2k / gist:4346691
Created December 20, 2012 16:56
a function to abort a class and cause all resource in the class to NOT be applied, without failing compilation like fail()
Puppet::Parser::Functions::newfunction(:failclass, :doc => 'Calling this function will immediately fail the class in current scope and mark all contained resources as failed.') do |args|
raise ArgumentError, ("failclass(): call with a single argument, the message.)") if args.length != 1
# build a resource
p_resource = Puppet::Parser::Resource.new(:whit, args[0], :scope => self, :source => resource)
# then add requirements to all other resources in scope.
# how do i select all resources in current scope?
compiler.catalog.resources.select{ |x| x[:scope] == self }.each do |res|
def in_puppet?
defined?(Puppet)
end
$users = [ 'billy', 'bob', 'thornton' ]
user { $users:
ensure => present,
}
<% scope.catalog.resources.select{|x| x.class? }.each do |klass| -%>
<%= klass.to_s %>
<% end -%>
[root@master ~]# puppet describe --list | grep rcsrepo
rcsrepo - .. no documentation ..
[root@master ~]# puppet describe rcsrepo
rcsrepo
=======
A local version control repository
$rand = fqdn_rand(59)
$puppet_crontime = "${rand} * * * *"
# <modulepath>/<somemodule>/lib/puppet/parser/functions/my_fqdn_rand.rb
Puppet::Parser::Functions.newfunction(
:my_fqdn_rand,
:type => :rvalue,
:doc => 'runs on ruby 1.9!'
) do |args|
raise ArgumentError, 'my_fqdn_rand: accepts only one argument' if args != 1
function_fqdn_rand(args[0].to_i)
end
class x {
$x1 = 'stuff'
include x::y
$x2 = 'more stuff'
}
class x::y {
notify { $x::x1: }
notify { $x::x2: }
}
@binford2k
binford2k / netserve.rb
Created August 1, 2013 20:50
simple mco agent
module MCollective
module Agent
class Netserv<RPC::Agent
metadata :name => "netserv",
:description => "Network services for MCollective",
:author => "Ben Ford",
:license => "GPLv2",
:version => "1.1",
:url => "http://www.puppetlabs.com.com/education",
:timeout => 60
# this should go in <module>/lib/puppet/parser/functions/filter_hash.rb
Puppet::Parser::Functions.newfunction(:filter_hash) do |args|
rv = {}
args[0].collect do |key, item|
rv[key] = { 'hostname' => item['hostname'], 'path' => item['path'] }
end
return rv
end