Skip to content

Instantly share code, notes, and snippets.

View duritong's full-sized avatar

duritong duritong

View GitHub Profile
%if 0%{?fedora} || 0%{?rhel} >= 5
BuildArch: noarch
Requires: ruby(abi) = 1.8
Requires: ruby-shadow
%endif
$ cat foo.pp
class a {
file{'/tmp/a': ensure => file}
file{'/tmp/b': ensure => file}
}
class b inherits a {
File['/tmp/b']{ensure => absent }
}
# Having masterzen's patch applied puppet still burns 100% cpu _after_ doing all the changes
# I use the following resource
file{'/home/duritong':
ensure => directory,
recurse => true,
backup => false,
checksum => none,
owner => 'duritong', group => 'duritong', mode => 0600;
$ facter | grep puppet
puppetversion => 2.6.1
$ cat lib/puppet/parser/functions/array_del.rb
Puppet::Parser::Functions::newfunction(
:array_del,
:type => :rvalue,
:doc => "Deletes items from an array
Example: array_del(['a','b'],'b') -> ['a']"
) do |args|
@duritong
duritong / puppetsh.rb
Created November 25, 2010 01:30
did it become that difficult?
require 'puppet/util/run_mode'
$puppet_application_mode = Puppet::Util::RunMode.new(:master)
require 'puppet'
require 'puppet/rails'
Puppet.settings.unsafe_parse('/etc/puppet/puppet.conf')
Puppet::Rails.connect
@duritong
duritong / puppet_template_inclusion
Created February 25, 2011 11:41
How can I access `state` in the included template?
#some_template.erb
<%- [:foo, :bar].each do |state| %>
<%= scope.function_template('some/other_template.erb') %>
<%- end %>
# some/other_template.erb
<%- if state == :foo %>
write something
<%- end %>
@duritong
duritong / site-puppet::cron
Created March 1, 2011 19:51
Hopefully this is the right chain
class site-puppet::cron inherits puppet::cron {
include site-puppet::cron::debian
}
class site-puppet::cron::debian inherits puppet::cron::linux {
if $hostname != 'puppetmaster' {
File['puppet_config']{ source => undef, content => template("site-puppet/client/puppet.conf") }
}
}
require 'rubygems'
require 'digest/sha2'
require 'active_support'
def password(pass)
salt = 32.times.collect { (i = Kernel.rand(62); i += ((i < 10) ? 48 : ((i < 36) ? 55 : 61 ))).chr }.join
"{SSHA512}#{ActiveSupport::Base64.encode64s(Digest::SHA512.digest(pass + salt)+salt)}"
end
@duritong
duritong / commands.rb
Created November 3, 2011 09:01 — forked from masterzen/commands.rb
Puppet Extension Point - part 2
commands ping => "/usr/bin/ping"
...
# we can use it later with:
# ping "www.puppetlabs.com"
@duritong
duritong / test.rb
Created November 29, 2011 16:49
ruby class var foo
require 'active_support'
module ModuleA
def self.included(c)
c.class_attribute :foo
c.extend ClassMethods
end
module ClassMethods
def set_foo(value)