Puppet Class: puppetmaster::gitclone

Defined in:
modules/puppetmaster/manifests/gitclone.pp

Overview

Class: puppetmaster::gitclone

This class handles the repositories from which the puppetmasters pull

Parameters

secure_private

If false, /etc/puppet/private will be labs/private.git. Otherwise, some magic is done to have local repositories and sync between puppetmasters.

is_git_master

If True, the git private repository here will be considered a master.

prevent_cherrypicks

If true, setup git hooks to prevent manual modification of the git repos.

user

The user which should own the git repositories

group

The group which should own the git repositories

Parameters:

  • secure_private (Any) (defaults to: true)
  • is_git_master (Any) (defaults to: false)
  • prevent_cherrypicks (Any) (defaults to: true)
  • user (Any) (defaults to: 'gitpuppet')
  • group (Any) (defaults to: 'gitpuppet')


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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
# File 'modules/puppetmaster/manifests/gitclone.pp', line 21

class puppetmaster::gitclone(
    $secure_private = true,
    $is_git_master = false,
    $prevent_cherrypicks = true,
    $user = 'gitpuppet',
    $group = 'gitpuppet',
){
    $servers = hiera('puppetmaster::servers', {})

    class  { '::puppetmaster::base_repo':
        gitdir   => $::puppetmaster::gitdir,
        gitowner => $user,
    }

    if $prevent_cherrypicks {
        $cherrypick_hook_ensure = present
    } else {
        $cherrypick_hook_ensure = absent
    }

    file {
        "${puppetmaster::gitdir}/operations/puppet/.git/hooks/post-merge":
            ensure  => absent;
        "${puppetmaster::gitdir}/operations/puppet/.git/hooks/pre-commit":
            ensure  => $cherrypick_hook_ensure,
            require => Git::Clone['operations/puppet'],
            owner   => $user,
            group   => $group,
            source  => 'puppet:///modules/puppetmaster/git/pre-commit',
            mode    => '0550';
        "${puppetmaster::gitdir}/operations/puppet/.git/hooks/pre-merge":
            ensure  => $cherrypick_hook_ensure,
            require => Git::Clone['operations/puppet'],
            owner   => $user,
            group   => $group,
            source  => 'puppet:///modules/puppetmaster/git/pre-merge',
            mode    => '0550';
        "${puppetmaster::gitdir}/operations/puppet/.git/hooks/pre-rebase":
            ensure  => $cherrypick_hook_ensure,
            require => Git::Clone['operations/puppet'],
            owner   => $user,
            group   => $group,
            source  => 'puppet:///modules/puppetmaster/git/pre-rebase',
            mode    => '0550';
        "${puppetmaster::gitdir}/operations/software/.git/hooks/pre-commit":
            ensure  => $cherrypick_hook_ensure,
            require => Git::Clone['operations/software'],
            owner   => $user,
            group   => $group,
            source  => 'puppet:///modules/puppetmaster/git/pre-commit',
            mode    => '0550';
        $puppetmaster::volatiledir:
            ensure => directory,
            owner  => 'root',
            group  => 'puppet',
            mode   => '0750';
        "${puppetmaster::volatiledir}/misc":
            ensure => directory,
            owner  => 'root',
            group  => 'puppet',
            mode   => '0750';
    }

    if $secure_private {
        # Set up private repo.
        # Note that puppet does not actually clone the repo -- puppetizing that
        # turns out to be a big, insecure mess.
        #
        # However, it is enough to push from the private repo master
        # in order to create the repo.

        # on any master for private data,
        # /srv/private contains the actual repository.
        # On the non-masters, it is a bare git repo used only to receive
        # the push from upstream

        if $is_git_master {
            file { '/srv/private':
                ensure  => directory,
                owner   => $user,
                group   => $group,
                mode    => '0640', # Will become 0755 for dir automatically
                recurse => true,
            }

            # On a private master, /srv/private is a real repository
            exec { '/srv/private init':
                command => '/usr/bin/git init',
                user    => 'root',
                group   => 'root',
                cwd     => '/srv/private',
                creates => '/srv/private/.git',
                require => File['/srv/private'],
            }
            # Ssh wrapper to use the gitpuppet private key
            file { '/srv/private/.git/ssh_wrapper.sh':
                ensure  => present,
                source  => 'puppet:///modules/puppetmaster/git/private/ssh_wrapper.sh',
                owner   => 'root',
                group   => 'root',
                mode    => '0555',
                require => Exec['/srv/private init'],
            }

            # Audit hook, add username of commiter in message
            file { '/srv/private/.git/hooks/commit-msg':
                ensure  => present,
                source  => 'puppet:///modules/puppetmaster/git/private/commit-msg-master',
                owner   => $user,
                group   => $group,
                mode    => '0550',
                require => Exec['/srv/private init'],
            }

            # Syncing hooks
            # This hook updates /var/lib and pushes changes to the backend workers
            file { '/srv/private/.git/hooks/post-commit':
                ensure  => present,
                content => template('puppetmaster/git-master-postcommit.erb'),
                owner   => $user,
                group   => $group,
                mode    => '0550',
                require => Exec['/srv/private init'],
            }

            # Post receive script in case the push is from another master
            # This will reset to head, and transmit data to /var/lib
            file { '/srv/private/.git/hooks/post-receive':
                source  => 'puppet:///modules/puppetmaster/git/private/post-receive-master',
                owner   => $user,
                group   => $group,
                mode    => '0550',
                require => File['/srv/private'],
            }
            file { '/srv/private/.git/config':
                source  => 'puppet:///modules/puppetmaster/git/private/gitconfig-master',
                owner   => $user,
                group   => $group,
                mode    => '0550',
                require => File['/srv/private'],
            }
        } else {
            puppetmaster::gitprivate { '/srv/private':
                bare     => true,
                dir_mode => '0700',
                owner    => $user,
                group    => $group,
            }

            # This will transmit data to /var/lib...
            file { '/srv/private/hooks/post-receive':
                source  => 'puppet:///modules/puppetmaster/git/private/post-receive',
                owner   => $user,
                group   => $group,
                mode    => '0550',
                require => Puppetmaster::Gitprivate['/srv/private'],
            }
        }

        # What is in the private repo must also be in operations/private in
        # /var/lib/git...

        $private_dir = "${puppetmaster::gitdir}/operations/private"

        puppetmaster::gitprivate { $private_dir:
            origin   => '/srv/private',
            owner    => $user,
            group    => 'puppet',
            dir_mode => '0750',
        }

        if $is_git_master {
            Exec['/srv/private init'] -> Puppetmaster::Gitprivate[$private_dir]
        } else {
            Puppetmaster::Gitprivate['/srv/private'] -> Puppetmaster::Gitprivate[$private_dir]
        }

        # ...and linked to /etc/puppet
        file { '/etc/puppet/private':
                ensure => link,
                target => "${puppetmaster::gitdir}/operations/private",
                force  => true;
        }
    } else {
        file { '/var/lib/git/labs':
            ensure => directory,
            owner  => $user,
            group  => $group,
            mode   => '0755',
        }

        git::clone { 'labs/private':
            require   => File["${puppetmaster::gitdir}/labs"],
            owner     => $user,
            group     => $group,
            directory => "${puppetmaster::gitdir}/labs/private",
        }

        file { '/etc/puppet/private':
            ensure => link,
            target => "${puppetmaster::gitdir}/labs/private",
            force  => true,
        }
    }

    git::clone {
        'operations/software':
            require   => File["${puppetmaster::gitdir}/operations"],
            owner     => $user,
            group     => $group,
            directory => "${puppetmaster::gitdir}/operations/software",
            origin    => 'https://gerrit.wikimedia.org/r/p/operations/software';
    }

    # These symlinks will allow us to use /etc/puppet for the puppetmaster to
    # run out of.
    file { '/etc/puppet/templates':
        ensure => link,
        target => "${puppetmaster::gitdir}/operations/puppet/templates",
        force  => true,
    }
    file { '/etc/puppet/files':
        ensure => link,
        target => "${puppetmaster::gitdir}/operations/puppet/files",
        force  => true,
    }
    file { '/etc/puppet/manifests':
        ensure => link,
        target => "${puppetmaster::gitdir}/operations/puppet/manifests",
        force  => true,
    }
    file { '/etc/puppet/modules':
        ensure => link,
        target => "${puppetmaster::gitdir}/operations/puppet/modules",
        force  => true,
    }
    file { '/etc/puppet/hieradata':
        ensure => link,
        target => "${puppetmaster::gitdir}/operations/puppet/hieradata",
        force  => true,
    }
    file { '/etc/puppet/environments':
        ensure => link,
        target => "${puppetmaster::gitdir}/operations/puppet/environments",
        force  => true,
    }
}