Defined Type: mrepo::repo

Defined in:
manifests/repo.pp

Overview

This define creates and manages an mrepo repository. It generates an mrepo repository file definition and will generate the initial repository. If the update parameter is set to “now”, the repository will be immediately synchronized.

Parameters

ensure

Creates or destroys the given repository Values: present,absent

release

The distribution release to mirror Example (RHN): 6

arch

The architecture of the release to mirror. Values: i386, i586, x86_64, ppc, s390, s390x, ia64

urls

A hash of repository names and URLs.

metadata

The metadata type for the repository. More than one value can be used in an array. Default: repomd Values: yum,apt,repomd,repoview

update

The schedule for updating.The ‘now’ will update the repo on every run of puppet. Be warned that this could be a very lengthy process on the first run. Default: nightly Values: now, nightly, weekly, never

hour

The hour to run the sync. Optional. Default: 0

iso

The pattern of the ISO to mirror. Optional.

rhn

Whether to generate rhn metadata for these repos. Default: false

type

The type of the repo: std, ncc, rhn Default: std

typerelease

The name of the release as understood by mrepo. Example (RHN): 6Server Default: undef

repotitle

The human readable title of the repository. Default: $name

gen_timeout

The number of seconds to allow mrepo to generate the initial repository. Default: 1200

sync_timeout

The number of seconds to allow mrepo to sync a repository. Default: 3600

mrepo_env

Environment passed to the mrepo command Default: undef

mrepo_command

Mrepo command string Default: /usr/bin/mrepo

mrepo_options

Options passed to the mrepo command Default: -qgu (Quiet, Generate, Update)

mrepo_logging

Can be used to redirect output to a logfile for later inspection Default: undef

Examples

mrepo::repo { “centos5-x86_64”:

ensure    => present,
arch      => "x86_64",
release   => "5.5",
repotitle => "CentOS 5.5 64 bit",
urls      => {
  addons      => "http://mirrors.kernel.org/centos/5.6/addons/x86_64/",
  centosplus  => "http://mirrors.kernel.org/centos/5.6/centosplus/x86_64/",
  contrib     => "http://mirrors.kernel.org/centos/5.6/contrib/x86_64/",
  extras      => "http://mirrors.kernel.org/centos/5.6/extras/x86_64/",
  fasttrack   => "http://mirrors.kernel.org/centos/5.6/fasttrack/x86_64/",
  updates     => "http://mirrors.kernel.org/centos/5.6/updates/x86_64/",
}

}

Further examples can be found in the module README.

See Also

mrepo usage: github.com/dagwieers/mrepo/blob/master/docs/usage.txt

For rhn mirroring, see README.redhat.markdown

Author

Adrien Thebo <adrien@puppetlabs.com>

Copyright 2011 Puppet Labs, unless otherwise noted

Parameters:

  • ensure (Enum['present', 'absent'])
  • release (String[1])
  • arch (Mrepo::Arch)
  • urls (Hash[String, String]) (defaults to: {})
  • metadata (Variant[Mrepo::Metadata,Array[Mrepo::Metadata]]) (defaults to: 'repomd')
  • update (Mrepo::Update) (defaults to: 'nightly')
  • hour (Variant[String[1], Integer]) (defaults to: '0')
  • minute (Variant[String[1], Integer]) (defaults to: '0')
  • iso (Optional[String[1]]) (defaults to: undef)
  • repotitle (String[1]) (defaults to: $name)
  • gen_timeout (Variant[String[1], Integer]) (defaults to: '1200')
  • sync_timeout (Variant[String[1], Integer]) (defaults to: '1200')
  • type (Enum['std', 'ncc', 'rhn']) (defaults to: 'std')
  • typerelease (Optional[String[1]]) (defaults to: undef)
  • mrepo_env (Optional[String[1]]) (defaults to: undef)
  • mrepo_command (Stdlib::Absolutepath) (defaults to: '/usr/bin/mrepo')
  • mrepo_options (String) (defaults to: '-qgu')
  • mrepo_logging (Optional[String[1]]) (defaults to: undef)
  • ncc_username (Optional[String[1]]) (defaults to: undef)
  • ncc_password (Optional[String[1]]) (defaults to: undef)


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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
# File 'manifests/repo.pp', line 117

define mrepo::repo (
  Enum['present', 'absent'] $ensure,
  String[1] $release,
  Mrepo::Arch $arch,
  Hash[String, String] $urls                                = {},
  Variant[Mrepo::Metadata,Array[Mrepo::Metadata]] $metadata = 'repomd',
  Mrepo::Update $update                                     = 'nightly',
  Variant[String[1], Integer] $hour                         = '0',
  Variant[String[1], Integer] $minute                       = '0',
  Optional[String[1]] $iso                                  = undef,
  String[1] $repotitle                                      = $name,
  Variant[String[1], Integer] $gen_timeout                  = '1200',
  Variant[String[1], Integer] $sync_timeout                 = '1200',
  Enum['std', 'ncc', 'rhn'] $type                           = 'std',
  Optional[String[1]] $typerelease                          = undef,
  Optional[String[1]] $mrepo_env                            = undef,
  Stdlib::Absolutepath $mrepo_command                       = '/usr/bin/mrepo',
  String $mrepo_options                                     = '-qgu',
  Optional[String[1]] $mrepo_logging                        = undef,
  Optional[String[1]] $ncc_username                         = undef,
  Optional[String[1]] $ncc_password                         = undef,
) {
  include mrepo

  # mrepo tries to be clever, and if the arch is the suffix of the name will
  # fold the two, but if the name isn't x86_64 or i386, no folding occurs.
  # This manages the inconsistent behavior.
  $real_name = mrepo_munge($name, $arch)

  $src_root        = $mrepo::src_root
  $www_root        = $mrepo::www_root
  $src_root_subdir = "${src_root}/${real_name}"
  $www_root_subdir = "${www_root}/${real_name}"

  $user  = $mrepo::user
  $group = $mrepo::group

  case $ensure {
    'present': {
      file { "/etc/mrepo.conf.d/${name}.conf":
        ensure  => file,
        owner   => $user,
        group   => $group,
        content => template('mrepo/repo.conf.erb'),
        require => Class['mrepo::package'],
      }

      file { $src_root_subdir:
        ensure  => directory,
        owner   => $user,
        group   => $group,
        mode    => '0755',
        backup  => false,
        recurse => false,
      }

      exec { "Generate mrepo repo ${name}":
        command   => "mrepo -g ${name}",
        cwd       => $src_root,
        path      => ['/usr/bin', '/bin'],
        user      => $user,
        group     => $group,
        creates   => $www_root_subdir,
        timeout   => $gen_timeout,
        require   => Class['mrepo::package'],
        subscribe => File["/etc/mrepo.conf.d/${name}.conf"],
        logoutput => on_failure,
      }

      if $mrepo_env {
        $repo_command = "${mrepo_env} ${mrepo_command} ${mrepo_options} ${name} ${mrepo_logging}"
      }
      else {
        $repo_command = "${mrepo_command} ${mrepo_options} ${name} ${mrepo_logging}"
      }

      case $update {
        'now': {
          exec { "Synchronize repo ${name}":
            command   => $repo_command,
            cwd       => $src_root,
            path      => ['/usr/bin', '/bin'],
            user      => $user,
            group     => $group,
            timeout   => $sync_timeout,
            require   => Class['mrepo::package'],
            logoutput => on_failure,
          }
          cron { "Nightly synchronize repo ${name}":
            ensure => absent,
            user   => $user,
          }
          cron { "Weekly synchronize repo ${name}":
            ensure => absent,
            user   => $user,
          }
        }
        'nightly': {
          cron { "Nightly synchronize repo ${name}":
            ensure  => present,
            command => $repo_command,
            hour    => $hour,
            minute  => $minute,
            user    => $user,
            require => Class['mrepo::package'],
          }
          cron { "Weekly synchronize repo ${name}":
            ensure => absent,
            user   => $user,
          }
        }
        'weekly': {
          cron { "Weekly synchronize repo ${name}":
            ensure  => present,
            command => $repo_command,
            weekday => '0',
            hour    => $hour,
            minute  => $minute,
            user    => $user,
            require => Class['mrepo::package'],
          }
          cron { "Nightly synchronize repo ${name}":
            ensure => absent,
            user   => $user,
          }
        }
        default: {
        }
      }

      case $type {
        'ncc': {
          create_resources( 'mrepo::repo::ncc',
            { "${name}"      => {
                ensure       => $ensure,
                release      => $release,
                arch         => $arch,
                ncc_username => $ncc_username,
                ncc_password => $ncc_password,
                urls         => $urls,
                metadata     => $metadata,
                update       => $update,
                hour         => $hour,
                iso          => $iso,
                repotitle    => $repotitle,
                typerelease  => $typerelease,
              }
            }
          )
        }
        'rhn': {
          create_resources( 'mrepo::repo::rhn',
            { "${name}"     => {
                ensure      => $ensure,
                release     => $release,
                arch        => $arch,
                urls        => $urls,
                metadata    => $metadata,
                update      => $update,
                hour        => $hour,
                iso         => $iso,
                repotitle   => $repotitle,
                typerelease => $typerelease,
              }
            }
          )
        }
        default: {
          # don't do anything for 'std'
        }
      }
    }
    'absent': {
      exec { "Unmount any mirrored ISOs for ${name}":
        command   => "umount ${www_root_subdir}/disc*",
        path      => ['/usr/bin', '/bin', '/usr/sbin', '/sbin'],
        onlyif    => "mount | grep ${www_root_subdir}/disc",
        provider  => shell,
        logoutput => true,
      }
      file { $www_root_subdir:
        ensure  => absent,
        backup  => false,
        recurse => false,
        force   => true,
        before  => File[$src_root_subdir],
        require => Exec["Unmount any mirrored ISOs for ${name}"],
      }
      file { $src_root_subdir:
        ensure  => absent,
        backup  => false,
        recurse => false,
        force   => true,
      }
      file { "/etc/mrepo.conf.d/${name}":
        ensure => absent,
        backup => false,
        force  => true,
      }
      cron { "Nightly synchronize repo ${name}":
        ensure => absent,
        user   => $user,
      }
      cron { "Weekly synchronize repo ${name}":
        ensure => absent,
        user   => $user,
      }
    }
    default: {
    }
  }
}