Sha256: 6962d10e8c9f2c44f26eb3f0b83e536af68db534d420b3e42b2809e237fc4554

Contents?: true

Size: 1.38 KB

Versions: 2

Compression:

Stored size: 1.38 KB

Contents

require 'shellwords'

include_recipe 'command'

node.reverse_merge!(
  certbot: {
    challenge_type: 'http-01',
    authenticator: 'standalone',
    debug_mode: false,
    snappy_executable: '/snap/bin/certbot',
    live_dir: '/etc/letsencrypt/live',
  }
)

node.validate! do
  {
    certbot: {
      challenge_type: string,
      authenticator: string,
      debug_mode: boolean,
      snappy_executable: string,
      live_dir: string,

      domains: array_of(string),
      email: string,
      webroot_path: optional(string),
    }
  }
end

package 'snapd'

snappy 'certbot' do
  classic true
end

link node[:certbot][:command] do
  to node[:certbot][:snappy_executable]
end

# get each domain certificate
node[:certbot][:domains].each do |domain|
  execute "get #{domain} certificate" do
    cmd = [
      node[:certbot][:command],
      'certonly',
      '--agree-tos',
      "--domain", domain,
      "-m", node[:certbot][:email],
      '-n', # Run non-interactively
      '--keep',
      "--authenticator", node[:certbot][:authenticator],
      "--preferred-challenges", node[:certbot][:challenge_type],
    ]
    cmd += ["--webroot", node[:certbot][:webroot_path]] if node[:certbot][:webroot_path]
    cmd << '--debug' if node[:certbot][:debug_mode]
    command cmd.shelljoin

    dir = File.join(node[:certbot][:live_dir], domain)
    exists = ["test", "-d", dir].shelljoin
    not_if exists
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
itamae-plugin-recipe-certbot-0.3.1 lib/itamae/plugin/recipe/certbot/get.rb
itamae-plugin-recipe-certbot-0.3.0 lib/itamae/plugin/recipe/certbot/get.rb