# conditional # $hostname == master case $hostname { master : { # Variables $ha_nodenames = generate('/usr/bin/env', '/var/lib/gems/1.8/bin/server-list-active', '-c', 'name') $ha_node_ips = generate('/usr/bin/env', '/var/lib/gems/1.8/bin/server-list-active', '-c', 'ip') $ha_timeout = '5s' $ha_port = '80' # exec exec { "heartbeat-update-cib": command => '/usr/sbin/cibadmin -R -x /etc/ha.d/cib.xml', path => '/usr/bin:/bin:/usr/local/bin:$PATH', refreshonly => true } # package # heartbeat-2 class heartbeat-2 { # remotefile file { "/etc/ha.d/ha.cf": ensure => 'present', require => Package['heartbeat-2'], mode => 444, name => '/etc/ha.d/ha.cf', notify => Service["heartbeat"], content => template("ha.cf"), owner => 'root' } file { "/etc/ha.d/authkeys": ensure => 'present', require => Package['heartbeat-2'], mode => 400, name => '/etc/ha.d/authkeys', notify => Service["heartbeat"], content => template("authkeys"), owner => 'root' } file { "/etc/ha.d/cib.xml": ensure => 'present', require => Package['heartbeat-2'], mode => 444, name => '/etc/ha.d/cib.xml', notify => Exec["heartbeat-update-cib"], content => template("cib.xml"), owner => 'root' } # service service { "heartbeat": enable => true, hasstatus => true, ensure => 'running', require => Package['heartbeat-2'], name => 'heartbeat' } } include heartbeat-2 package { "heartbeat-2": ensure => 'present', name => 'heartbeat-2' } } default : {} } # $hostname == master case $hostname { master : { # exec exec { "update pem for heartbeat": command => 'scp /etc/puppet/ssl/ca/ca_crl.pem root@192.168.0.1:/etc/puppet/ssl/ca', path => '/usr/bin:/bin:/usr/local/bin:$PATH', refreshonly => true } } default : {} } # $hostname == master case $hostname { master : { # Variables $name_haproxy = 'test' $nodenames_haproxy = generate('/usr/bin/env', '/var/lib/gems/1.8/bin/server-list-active', '-c', 'name') $node_ips_haproxy = generate('/usr/bin/env', '/var/lib/gems/1.8/bin/server-list-active', '-c', 'ip') $ports_haproxy = [ '80' ] $forwarding_port = '8080' $proxy_mode = 'http' # remotefile file { "/etc/haproxy.cfg": ensure => 'present', require => Package["haproxy"], mode => 644, name => '/etc/haproxy.cfg', notify => Service["haproxy"], content => template("haproxy.conf"), owner => 'root' } # call_function line { '/etc/default/haproxy_line' : file => '/etc/default/haproxy', line => 'ENABLED=1', ensure => 'present' } line { '/etc/default/syslogd_line' : file => '/etc/default/syslogd', line => 'SYSLOGD="-r"', ensure => 'present' } line { '/etc/syslog.conf_line' : file => '/etc/syslog.conf', line => 'local0.* /var/log/haproxy.log', notify => Service["sysklogd"], ensure => 'present' } # package package { "haproxy": ensure => 'installed', name => 'haproxy' } # service service { "sysklogd": enable => true, ensure => [ 'running', 'running' ], name => 'sysklogd' } service { "haproxy": enable => true, ensure => 'running', name => 'haproxy' } } default : {} } # $hostname == master case $hostname { master : { # exec exec { ". /etc/profile && server-start-master": path => '/usr/bin:/bin:/usr/local/bin:$PATH' } # cron cron { "": command => '. /etc/profile && which cloud-maintain | /bin/sh', ensure => 'present', minute => '*/3', user => 'root' } } default : {} } # heartbeat class heartbeat { } include heartbeat # haproxy class haproxy { } include haproxy # ruby class ruby { # call_function line { '/etc/profile_line' : file => '/etc/profile', line => 'export PATH=$PATH:/var/lib/gems/1.8/bin:/sbin', ensure => 'present' } # package package { "libreadline-ruby1.8": ensure => 'present', name => 'libreadline-ruby1.8' } package { "libruby1.8": ensure => 'present', name => 'libruby1.8' } package { "ruby1.8-dev": ensure => 'present', name => 'ruby1.8-dev' } package { "ruby1.8": ensure => 'present', name => 'ruby1.8' } } include ruby # poolparty class poolparty { # host host { "master": ensure => 'present', name => 'master', ip => '192.168.0.1' } host { "node1": ensure => 'present', name => 'node1', ip => '192.168.0.1' } # cron cron { "puppetd runner": command => '. /etc/profile && /usr/sbin/puppetd --onetime --no-daemonize --logdest syslog --server master 2>&1', ensure => 'present', name => 'puppetd runner', minute => [ 0, 15, 30, 45 ], user => 'root' } # package package { "erlang": ensure => 'present', name => 'erlang' } package { "erlang-dev": ensure => 'present', name => 'erlang-dev' } package { "erlang-src": ensure => 'present', name => 'erlang-src' } # rubygems class rubygems { # gempackage # logging class logging { # exec exec { "logging": command => 'gem install -y --no-ri --no-rdoc logging', require => Package['rubygems'], path => '/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/var/lib/gems/1.8/bin', cwd => '/tmp', unless => 'gem list --local logging | grep logging ' } } include logging # xml-simple class xml-simple { # exec exec { "xml-simple": command => 'gem install -y --no-ri --no-rdoc xml-simple', require => Package['rubygems'], path => '/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/var/lib/gems/1.8/bin', cwd => '/tmp', unless => 'gem list --local xml-simple | grep xml-simple ' } # gempackage # grempe-amazon-ec2 class grempe-amazon-ec2 { # exec exec { "grempe-amazon-ec2": command => 'gem install -y --no-ri --no-rdoc --source http://gems.github.com grempe-amazon-ec2', require => Exec['xml-simple'], path => '/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/var/lib/gems/1.8/bin', cwd => '/tmp', unless => 'gem list --local grempe-amazon-ec2 | grep grempe-amazon-ec2 ' } } include grempe-amazon-ec2 } include xml-simple # rake class rake { # exec exec { "rake": command => 'gem install -y --no-ri --no-rdoc rake', require => Package['rubygems'], path => '/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/var/lib/gems/1.8/bin', cwd => '/tmp', unless => 'gem list --local rake | grep rake ' } } include rake # hoe class hoe { # exec exec { "hoe": command => 'gem install -y --no-ri --no-rdoc hoe', require => Package['rubygems'], path => '/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/var/lib/gems/1.8/bin', cwd => '/tmp', unless => 'gem list --local hoe | grep hoe ' } # gempackage # open4 class open4 { # exec exec { "open4": command => 'gem install -y --no-ri --no-rdoc open4', require => Exec['hoe'], path => '/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/var/lib/gems/1.8/bin', cwd => '/tmp', unless => 'gem list --local open4 | grep open4 ' } } include open4 # ParseTree class parsetree { # exec exec { "ParseTree": command => 'gem install -y --no-ri --no-rdoc --version 2.2.0 ParseTree', require => Exec['hoe'], path => '/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/var/lib/gems/1.8/bin', cwd => '/tmp', unless => 'gem list --local ParseTree | grep ParseTree | grep 2.2.0' } # gempackage # ruby2ruby class ruby2ruby { # exec exec { "ruby2ruby": command => 'gem install -y --no-ri --no-rdoc ruby2ruby', require => Exec['ParseTree'], path => '/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/var/lib/gems/1.8/bin', cwd => '/tmp', unless => 'gem list --local ruby2ruby | grep ruby2ruby ' } } include ruby2ruby # activesupport class activesupport { # exec exec { "activesupport": command => 'gem install -y --no-ri --no-rdoc activesupport', require => Exec['ParseTree'], path => '/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/var/lib/gems/1.8/bin', cwd => '/tmp', unless => 'gem list --local activesupport | grep activesupport ' } # gempackage # auser-poolparty class auser-poolparty { # exec exec { "build_messenger": command => '. /etc/profile && server-build-messenger', require => Exec['auser-poolparty'], path => '/usr/bin:/bin:/usr/local/bin:$PATH' } exec { "start_node": command => '. /etc/profile && server-start-node', require => [ Exec['auser-poolparty'], Exec["build_messenger"] ], path => '/usr/bin:/bin:/usr/local/bin:$PATH' } exec { "auser-poolparty": command => 'gem install -y --no-ri --no-rdoc --source http://gems.github.com auser-poolparty', require => Exec['activesupport'], path => '/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/var/lib/gems/1.8/bin', cwd => '/tmp', unless => 'gem list --local auser-poolparty | grep auser-poolparty ' } } include auser-poolparty } include activesupport # RubyInline class rubyinline { # exec exec { "RubyInline": command => 'gem install -y --no-ri --no-rdoc RubyInline', require => Exec['ParseTree'], path => '/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/var/lib/gems/1.8/bin', cwd => '/tmp', unless => 'gem list --local RubyInline | grep RubyInline ' } } include RubyInline } include ParseTree } include hoe } include rubygems package { "rubygems": ensure => 'present', name => 'rubygems' } } include poolparty # Custom functions define line($file, $line, $ensure = 'present', $notify=[]) { case $ensure { default: { err ( "unknown ensure value ${ensure}" ) } present: { exec { "/usr/bin/env echo '${line}' >> '${file}'": unless => "/usr/bin/env grep -qFx '${line}' '${file}'", notify => $notify } } absent: { exec { "/usr/bin/env sed -i '' -e '/^${line}$/d' '${file}'": onlyif => "/usr/bin/env grep -qFx '${line}' '${file}'", notify => $notify } } } } define append_if_no_such_line($file, $line, $refreshonly = 'false') { exec { "/bin/echo '$line' >> '$file'": unless => "/bin/grep -Fxqe '$line' '$file'", path => "/bin", refreshonly => $refreshonly, } } define delete_lines($file, $pattern) { exec { "sed -i -r -e '/$pattern/d' $file": path => "/bin", onlyif => "/bin/grep -E '$pattern' '$file'", } } # Serve subversion-based code from a local location. The job of this # module is to check the data out from subversion and keep it up to # date, especially useful for providing data to your Puppet server. define svnserve($source, $path, $user = false, $password = false) { file { $path: ensure => directory, owner => root, group => root } $svncmd = $user ? { false => "/usr/bin/svn co --non-interactive $source/$name .", default => "/usr/bin/svn co --non-interactive --username $user --password '$password' $source/$name ." } exec { "svnco-$name": command => $svncmd, cwd => $path, require => File[$path], creates => "$path/.svn" } exec { "svnupdate-$name": command => "/usr/bin/svn update", require => Exec["svnco-$name"], onlyif => '/usr/bin/svn status -u --non-interactive | /bin/grep "*"', cwd => $path } }