summaryrefslogtreecommitdiff
path: root/manifests/init.pp
blob: b16eac37438fecddec023922d95816cd6b6ae3a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#
# puppet module
# modules/puppet/manifests/init.pp - manage puppet stuff
# original by luke kanies
# http://github.com/lak
# adapted by puzzle itc
# merged with immerda project group's
# solution
#
# Copyright 2008, admin(at)immerda.ch
# Copyright 2008, Puzzle ITC GmbH
# Marcel Härry haerry+puppet(at)puzzle.ch
# Simon Josi josi+puppet(at)puzzle.ch
#
# This program is free software; you can redistribute 
# it and/or modify it under the terms of the GNU 
# General Public License version 3 as published by 
# the Free Software Foundation.
#

# modules_dir { "puppet": }

class puppet {
    case $kernel {
        linux: { 
            case $operatingsystem {
                gentoo:  { include puppet::gentoo }
                centos:  { include puppet::centos }
                debian:  { include puppet::debian }
                default: { include puppet::linux}
            }
        }
        openbsd: { include puppet::openbsd }
        default: { include puppet::base }
    }

}

class puppet::base {
    $real_puppet_config = $puppet_config ? {
        '' => "/etc/puppet/puppet.conf",
        default => $puppet_config,
    }

    file { 'puppet_config':
        path => "$real_puppet_config",
        source => [ "puppet://$server/files/puppet/client/${fqdn}/puppet.conf",
                "puppet://$server/files/puppet/client/puppet.conf.$operatingsystem",
                "puppet://$server/files/puppet/client/puppet.conf",
                "puppet://$server/puppet/client/puppet.conf.$operatingsystem",
                "puppet://$server/puppet/client/puppet.conf" ],
        notify => Service[puppet],
        owner => root, group => 0, mode => 600;
    }
    service{'puppet':
        ensure => running,
        enable => true,
        hasstatus => true,
        hasrestart => true,
        pattern => puppetd,
    }

}

class puppet::linux inherits puppet::base {
    package{ [ 'puppet', 'facter' ]:
        ensure => present,
    }

    # package bc needed for cron
    include bc
    Service['puppet']{
        require => Package[puppet],
    }


    file{'/etc/cron.d/puppetd.cron':
        source => [ "puppet://$server/puppet/cron.d/puppetd.${operatingsystem}",
                    "puppet://$server/puppet/cron.d/puppetd" ],
        owner => root, group => 0, mode => 0644;
    }
}
class puppet::gentoo inherits puppet::linux {
    Package[puppet]{
        category => 'app-admin',
    }
    Package[facter]{
        category => 'dev-ruby',
    }
    # as we use sometimes the init script to test
    Service[puppet]{
        hasstatus => false,
    }
}
class puppet::debian inherits puppet::linux {
    file{'/etc/default/puppet':
        source => [ "puppet://$server/files/puppet/client/debian/${fqdn}/puppet",
                    "puppet://$server/files/puppet/client/debian/${domain}/puppet",
                    "puppet://$server/files/puppet/client/debian/puppet",
                    "puppet://$server/puppet/client/debian/puppet" ],
        notify => Service[puppet],
        owner => root, group => 0, mode => 0644;
    }    # there is really no status cmd for it
    Service[puppet]{
        hasstatus => false,
    }
    File['/etc/cron.d/puppetd.cron']{
        path => '/etc/cron.d/puppetd',
    }
}

class puppet::centos inherits puppet::linux {
    file{'/etc/sysconfig/puppet':
        source => [ "puppet://$server/files/puppet/sysconfig/${fqdn}/puppet",
                    "puppet://$server/files/puppet/sysconfig/${domain}/puppet",
                    "puppet://$server/files/puppet/sysconfig/puppet",
                    "puppet://$server/puppet/sysconfig/puppet" ],
        notify => Service[puppet],
        owner => root, group => 0, mode => 0644;
    }
}
class puppet::openbsd inherits puppet::base {
    Service['puppet']{
        restart => '/bin/kill -HUP `/bin/cat /var/run/puppet/puppetd.pid`',
        stop => '/bin/kill `/bin/cat /var/run/puppet/puppetd.pid`',
        start => '/usr/local/bin/puppetd',
        hasstatus => false,
        hasrestart => false,
    }
    openbsd::add_to_rc_local{'puppetd':
        binary => '/usr/local/bin/puppetd',
    }
    cron { 'puppetd_check':
        command => '/bin/ps ax | /usr/bin/grep -v grep | /usr/bin/grep -q puppetd || (sleep `echo $RANDOM/2000*60 | bc` && /usr/local/bin/puppetd)',
        user => root,
        minute => 0,
    }
    cron { 'puppetd_restart':
        command => 'sleep `echo $RANDOM/2000*60 | bc` && /bin/kill `/bin/cat /var/run/puppet/puppetd.pid`; /usr/local/bin/puppetd',
        minute => 0,
        hour => 22,
        monthday => '*/2',
    } 
}