Skip to content

Instantly share code, notes, and snippets.

require 'digest/md5'
module Puppet::Parser::Functions
newfunction(:md5_splay, :type => :rvalue) do |args|
raise(Puppet::ParseError, "md5_splay(): Wrong number of arguments " +
"given (#{args.size} for 2)") if args.size != 2
value = args[0]
modulo = args[1].to_i
return Digest::MD5.hexdigest(value).hex % modulo
module Puppet::Parser::Functions
require 'erb'
newfunction(:multitemplate, :type => :rvalue) do |args|
contents = nil
environment = compiler.environment
sources = args
sources.each do |file|
Puppet.debug("Looking for #{file} in #{environment}")
function test123() {
echo 122
}
# Empty VHosts to prevent:
# /etc/cron.daily/logrotate:
# [Sun Aug 12 06:25:01 2012] [warn] NameVirtualHost *:443 has no VirtualHosts
<VirtualHost *:80>
</VirtualHost>
<VirtualHost *:443>
</VirtualHost>
@richardc
richardc / node.yaml
Created January 18, 2013 14:22 — forked from llowder/node.yaml
module::master_gemlist:
arr-pm:
ensure: '0.0.7'
provider: 'gem'
backports:
ensure: '2.6.2'
provider: 'gem'
cabin:
ensure: '0.4.4'
provider: 'gem'
@richardc
richardc / README.md
Created January 26, 2013 03:34
idea for datacat type
datacat { '/etc/nagios/objects/hostgroups.cfg':
    template => "${module_name}/hostgroups.cfg.erb",
}

datacat_fragment { "${::fqdn} in device hostgroup":
    target => '/etc/nagios/objects/hostgroups.cfg',
    data   => {
        device => [ $::fqdn ],
    },

}

root@puppetdb:~# cat /etc/puppet/manifests/site.pp
@@nagios_host { "fishcakes":
check_command => undef,
}
root@puppetdb:~# puppet agent -vt
Info: Retrieving plugin
Info: Caching catalog for puppetdb
Info: Applying configuration version '1359673644'
node demo {
nagios::host::service { 'ping':
check_command => 'check_ping',
}
}
#!/bin/sh
rm /tmp/hosts.cfg
puppet apply -e 'nagios_host { "foo": target => "/tmp/hosts.cfg", check_command => "a_mistake" }'
grep check_command /tmp/hosts.cfg
# Not what we want - the resource doesn't change as undef doesn't make it
# through to the type to clear the value
puppet apply -e 'nagios_host { "foo": target => "/tmp/hosts.cfg", check_command => undef }'
grep check_command /tmp/hosts.cfg
$ cat site.pp
file { '/tmp/foo':
source => undef,
}
$ puppet master --compile --manifest=site.pp
Compiled catalog for --manifest=site.pp in environment production in 0.02 seconds
{
"document_type": "Catalog",
"data": {