Skip to content

Instantly share code, notes, and snippets.

View hunner's full-sized avatar

Hunter Haugen hunner

View GitHub Profile
[epel]
name=Extra Packages for Enterprise Linux 5 - $basearch
#baseurl=http://download.fedoraproject.org/pub/epel/5/$basearch
mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=epel-5&arch=$basearch
failovermethod=priority
enabled=1
gpgcheck=0
[epel-puppet]
name=epel puppet
[root@tdc00demo ~]# cat /etc/settings.php
<?php
$db_url = 'mysqli://user:pass@host/database';
?>
[root@tdc00demo ~]# cat settings_php.augtool
set /augeas/load/Phpvars/incl[last()+1] "/etc/settings.php"
load
[root@tdc00demo ~]# augtool --noload -if settings_php.augtool
augtool> print /augeas/load/Phpvars
/augeas/load/Phpvars
[root@training manifests]# puppet apply alpha.pp
notice: beta
notice: /Stage[before]/Beta/Notify[beta]/message: defined 'message' as 'beta'
notice: alpha
notice: /Stage[before]/Alpha/Notify[alpha]/message: defined 'message' as 'alpha'
notice: gamma
notice: /Stage[main]/Gamma/Notify[gamma]/message: defined 'message' as 'gamma'
notice: Finished catalog run in 0.08 seconds
[root@training manifests]# cat alpha.pp
stage { 'before': before => Stage['main'], }
hostclass 'jetty::services' do
#{
# "zakenregister-1.0"=>{"instances"=>"2", "groupid" => "nl.cjib.jetty"},
# "zakenregister-2.0"=>{"instances"=>"2", "groupid" => "nl.cjib.jetty"},
# "zakenregister-2.2"=>{"instances"=>"4", "groupid" => "nl.cjib.jetty"},
# "somethingelse-2.2"=>{"instances"=>"4", "groupid" => "nl.cjib.jetty"}
#}
services = scope.function_hiera_hash("services")
nexus_repo_url = scope.function_hiera("nexus_repo_url")
services.each do |service_version, params|
hostclass :base do
files = {
"/tmp/a" => "abc",
"/tmp/foo" => scope.function_template("foo.erb"),
"/tmp/bar" => ''
}
files.each do |filename, content|
file filename,
:content => content
end
Facter.add('maint_ip') do
setcode do
interfaces = Facter.value('interfaces').split(',')
maint_ip = nil
interfaces.each do |interface|
maint_ip = Facter.value('ipaddress_' + interface) if Facter.value('ipaddress_' + interface) =~ /^172.30/
end
maint_ip || Facter.value('ipaddress_eth0')
end
end
diff --git a/lib/puppet/parser/functions/hiera_hash.rb b/lib/puppet/parser/functions/hiera_hash.rb
index 5d49d59..237fa0f 100644
--- a/lib/puppet/parser/functions/hiera_hash.rb
+++ b/lib/puppet/parser/functions/hiera_hash.rb
@@ -21,7 +21,7 @@ module Puppet::Parser::Functions
hiera = Hiera.new(:config => config)
- if self.respond_to?("{}")
+ if self.respond_to?("[]")
@hunner
hunner / facts_search.rb
Created February 27, 2012 22:25
lib/puppet/face/facts_search.rb and lib/puppet/parser/functions/search.rb
#lib/puppet/parser/functions/search.rb
Puppet::Parser::Functions.newfunction(:search, :type => :rvalue) do |args|
require 'puppet/face'
environment = scope.lookupvar('::environment')
Puppet::Face[:facts_search, 'v0.0.1'].search(args.flatten, "environment=#{environment}")
end
#lib/puppet/face/facts_search.rb
require 'puppet/face'
def tags
@tags = get_meter("tags", resource).sort
@tags
end
@hunner
hunner / environment.rb
Created March 6, 2012 21:27
Puppet environment as a fact
Facter.add(:environment) do
setcode do
if defined? Puppet and Puppet.application_name == :agent
Puppet[:environment]
else
Facter::Util::Resolution.exec('puppet agent --configprint environment')
end
end
end