summaryrefslogtreecommitdiff
path: root/manifests/manage.pp
blob: e09621aedef0a3b0ce442daa9a8a56292d994aa2 (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
define certbot::manage(
  $pre_hook = '',
  $aliases  = "www.${name}",
  $ensure   = present,
  $email    = hiera('certbot::manage::email'),
  $size     = hiera('certbot::manage::size', '4096'),
){
  # Format aliases and strip wildcard attempts
  $list    = regsubst($aliases, ' ',  ' -d ', 'G')
  $strip   = regsubst($list,    '\*', 'www',  'G')
  $domains = $strip ? {
    ''      => '',
    default => "-d ${strip}",
  }

  file { "${::certbot::basedir}/${name}":
    ensure  => directory,
    owner   => 'root',
    group   => "${::certbot::owner}",
    mode    => '0750',
    require => Package["${::certbot::tool}"],
  }

  if $pre_hook != '' {
    $real_pre_hook = "${pre_hook} && "
  }

  # Make sure nginx is restarted and request a certificate
  exec { "certbot-${name}":
    command => "${real_pre_hook}${certbot::script_base}/${certbot::tool} certonly --webroot -w ${::certbot::basedir}/${name} -d ${name} ${domains} -m ${email} --rsa-key-size ${size} --agree-tos",
    creates => "/etc/letsencrypt/archive/${name}",
    require => File["${::certbot::basedir}/${name}"],
  }
}