Puppet Class: pkgng

Inherits:
pkgng::params
Defined in:
manifests/init.pp

Overview

This configures the PkgNG Package manager on FreeBSD systems, and adds support for managing packages with Puppet. This will eventually be in mainline FreeBSD, but for now, we are leaving the installation up to the adminstrator, since there is no going back.

If you have purge_repos_d as true - then you’ll have no repositories defined unless you define one. You want to do this as you’ll want this module to control repos anyway.

To install PkgNG, one can simply run the following: make -C /usr/ports/ports-mgmg/pkg install clean

Examples:

include pkgng

Parameters:

  • pkg_dbdir (Stdlib::Absolutepath) (defaults to: $pkgng::params::pkg_dbdir)

    Full path to database directory for pkg(8)

  • pkg_cachedir (Stdlib::Absolutepath) (defaults to: $pkgng::params::pkg_cachedir)

    Full path to cache directory for pkg(8)

  • portsdir (Stdlib::Absolutepath) (defaults to: $pkgng::params::portsdir)

    Full path to ports directory

  • options (Array[String]) (defaults to: [])

    Array of options to write to pkg.conf(5)

  • purge_repos_d (Boolean) (defaults to: true)

    Boolean when true removes unmanaged repos

  • repos (Hash) (defaults to: {})

    Hash of resources to pass to create_resources()



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
# File 'manifests/init.pp', line 23

class pkgng (
  Stdlib::Absolutepath $pkg_dbdir     = $pkgng::params::pkg_dbdir,
  Stdlib::Absolutepath $pkg_cachedir  = $pkgng::params::pkg_cachedir,
  Stdlib::Absolutepath $portsdir      = $pkgng::params::portsdir,
  Array[String]        $options       = [],
  Boolean              $purge_repos_d = true,
  Hash                 $repos         = {},
) inherits pkgng::params {

  unless $::kernel == 'FreeBSD' {
    fail("pkg() is not supported on ${::kernel}")
  }

  file { '/usr/local/etc/pkg.conf':
    content => template('pkgng/pkg.conf'),
    notify  => Exec['pkg update'],
  }

  # make sure repo config dir is present
  file { '/usr/local/etc/pkg':
    ensure => directory,
  }

  file { '/usr/local/etc/pkg/repos':
    ensure  => directory,
    recurse => true,
    purge   => $purge_repos_d,
  }

  # Triggered on config changes
  exec { 'pkg update':
    path        => '/usr/local/sbin',
    refreshonly => true,
    command     => 'pkg update -q -f',
  }

  Exec['pkg update']
  -> Package <| provider == 'pkgng' or provider == undef |>

  # expand all pkg repositories from hashtable
  create_resources('pkgng::repo', $repos)
}