Puppet Class: puppet::server::ca::import

Defined in:
manifests/server/ca/import.pp

Summary

Import existing CA into current server

Overview

Import existing CA into current server

Examples:

include puppet::server::ca::import

Parameters:

  • import_path (Stdlib::Unixpath)
  • dns_alt_names (Array[Stdlib::Fqdn]) (defaults to: ['puppet', $facts['networking']['fqdn']])
  • certname (Variant[Boolean, Stdlib::Fqdn]) (defaults to: true)

    Whether to use –certname parameter for import command or not. If set to true than $::fqdn will be used as certname. If set to false - no certname parameter (import command will generate random string). If set to string - provided provided string will be set as certname



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
# File 'manifests/server/ca/import.pp', line 16

class puppet::server::ca::import (
  Stdlib::Unixpath $import_path,
  Array[Stdlib::Fqdn] $dns_alt_names = ['puppet', $facts['networking']['fqdn']],
  Variant[Boolean, Stdlib::Fqdn] $certname = true,
) {
  include puppet::server::install
  include puppet::globals
  include puppet::params

  $import_cakey  = "${import_path}/ca_key.pem"
  $import_cacert = "${import_path}/ca_crt.pem"
  $import_cacrl  = "${import_path}/ca_crl.pem"

  $import_condition = [
    "test -f ${import_cakey}",
    "test -f ${import_cacert}",
    "test -f ${import_cacrl}",
  ]

  $cacert           = $puppet::globals::cacert
  $ca_public_files  = $puppet::globals::ca_public_files
  $ca_private_files = $puppet::globals::ca_private_files

  $ca_files         = $ca_public_files + $ca_private_files

  $subject_alt_names_param = $dns_alt_names[0] ? {
    Stdlib::Fqdn => join(['--subject-alt-names', join($dns_alt_names, ',')], ' '),
    default      => '',
  }

  $certname_param = $certname ? {
    Stdlib::Fqdn => "--certname ${certname}",
    true         => "--certname ${facts['networking']['fqdn']}",
    default      => '',
  }

  # These PKI assets shold be cleaned up before CA import
  $timestamp = Timestamp.new().strftime('%Y%m%dT%H%M%S')
  $ca_files.each |Stdlib::Unixpath $path| {
    exec { "backup ${path}":
      path    => '/bin:/usr/bin',
      command => "mv -n ${path} ${path}.${timestamp}",
      onlyif  => ["test -f ${path}"] + $import_condition,
      unless  => "diff -q ${import_cacert} ${cacert}",
      before  => Exec['puppetserver ca import'],
    }
  }

  exec { 'puppetserver ca import':
    path    => '/opt/puppetlabs/bin:/opt/puppetlabs/puppet/bin:/bin:/usr/bin',
    command => "puppetserver ca import ${subject_alt_names_param} ${certname_param} --private-key ${import_cakey} --cert-bundle ${import_cacert} --crl-chain ${import_cacrl}", # lint:ignore:140chars
    onlyif  => $import_condition,
    creates => $cacert,
  }

  Class['puppet::server::install'] -> Exec['puppetserver ca import']
}