Skip to content

Instantly share code, notes, and snippets.

View duritong's full-sized avatar

duritong duritong

View GitHub Profile
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 / 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") }
}
}
@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 / 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
$ 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|
# 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;
$ cat foo.pp
class a {
file{'/tmp/a': ensure => file}
file{'/tmp/b': ensure => file}
}
class b inherits a {
File['/tmp/b']{ensure => absent }
}
%if 0%{?fedora} || 0%{?rhel} >= 5
BuildArch: noarch
Requires: ruby(abi) = 1.8
Requires: ruby-shadow
%endif
package{'postgresql-server':
ensure => present,
}
service{'postgresql':
enable => true,
ensure => running,
hasstatus => true,
require => Package[postgresql-server],
}
file{'/var/lib/pgsql/data/pg_hba.conf':
NICE but not working:
site-mysql/init.pp
class site-mysql inherits mysql {
# operations user
mysql_user{'[email protected].%':
password_hash => "*DEE65258DA0F2513DE84AD4C1E15557C65602548"
}
mysql_grant{'[email protected].%':
privileges => 'all',