summaryrefslogtreecommitdiff
path: root/manifests/manage.pp
blob: 14366f8d5051409ef44ae1ce7a0049332c5893d2 (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
35
define certbot::manage(
  $pre_hook = '',
  $aliases  = "www.${name}",
  $ensure   = present,
  $plugin   = 'webroot',
  $email    = lookup('certbot::manage::email'),
  $size     = lookup('certbot::manage::size', undef, undef, '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 -n --${plugin} -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}"],
  }
}