From 4e9fb2d323dffc288a27d9cc918fc78de930ba5b Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sat, 11 Jul 2020 00:02:40 -0400 Subject: improve certbot provisioning script --- modules/certbot/files/bootstrap-certbot | 97 --------------------------------- modules/certbot/manifests/init.pp | 21 +++++-- modules/certbot/templates/certbot-tozt | 76 ++++++++++++++++++++++++++ 3 files changed, 93 insertions(+), 101 deletions(-) delete mode 100755 modules/certbot/files/bootstrap-certbot create mode 100755 modules/certbot/templates/certbot-tozt (limited to 'modules/certbot') diff --git a/modules/certbot/files/bootstrap-certbot b/modules/certbot/files/bootstrap-certbot deleted file mode 100755 index f0b43f4..0000000 --- a/modules/certbot/files/bootstrap-certbot +++ /dev/null @@ -1,97 +0,0 @@ -#!/usr/bin/env bash -set -eu -set -o pipefail - -config_dir="$1" -if systemctl is-active -q nginx; then - is_running=1 -else - is_running= -fi - -cleanup() { - if [ -z "$is_running" ]; then - systemctl stop nginx - fi - - if [ -e /etc/nginx/nginx.conf.backup ]; then - mv /etc/nginx/nginx.conf.backup /etc/nginx.conf - fi -} -trap cleanup EXIT - -mv /etc/nginx/nginx.conf /etc/nginx/nginx.conf.backup -cat > /etc/nginx/nginx.conf < File["${_config_dir}/renewal-hooks/deploy"]; "${_config_dir}/renewal-hooks/deploy/reload-cert": ensure => absent; - "/usr/local/bin/bootstrap-certbot": - source => 'puppet:///modules/certbot/bootstrap-certbot', + "/usr/local/bin/certbot-tozt": + content => template('certbot/certbot-tozt'), mode => '0755'; } exec { "initial certbot run": provider => shell, - command => "/usr/local/bin/bootstrap-certbot ${config_dir}", + command => "/usr/local/bin/certbot-tozt ${config_dir}", creates => "${_config_dir}/live", require => [ Package["certbot"], # not Class["nginx"], because of circular dependencies with nginx::site Package["nginx"], Package["certbot-nginx"], - File['/usr/local/bin/bootstrap-certbot'], + File['/usr/local/bin/certbot-tozt'], ], } } diff --git a/modules/certbot/templates/certbot-tozt b/modules/certbot/templates/certbot-tozt new file mode 100755 index 0000000..bdf1201 --- /dev/null +++ b/modules/certbot/templates/certbot-tozt @@ -0,0 +1,76 @@ +#!/usr/bin/env bash +set -eu +set -o pipefail + +config_dir="${1:-}" +if systemctl is-active -q nginx; then + is_running=1 +else + is_running= +fi + +cleanup() { + if [ -z "$is_running" ]; then + systemctl stop nginx + fi + + if [ -e /etc/nginx/nginx.conf.backup ]; then + mv /etc/nginx/nginx.conf.backup /etc/nginx.conf + fi +} +trap cleanup EXIT + +mv /etc/nginx/nginx.conf /etc/nginx/nginx.conf.backup +cat > /etc/nginx/nginx.conf <; + location / { + root /tmp; + } + } +<%- @secondary_domains.each do |domain| -%> + server { + listen 80; + server_name <%= domain %>; + location / { + root /tmp; + } + } +<%- end -%> +} +EOF + +if [ -z "$is_running" ]; then + systemctl start nginx +fi + +if [ -z "$config_dir" ]; then + /usr/bin/certbot run \ + -n \ + --agree-tos \ + -m doy@tozt.net \ + --cert-name <%= @primary_domain %> \ + -d <%= @primary_domain %> \ +<%- @secondary_domains.each do |domain| -%> + -d <%= domain %> \ +<%- end -%> + --nginx +else + /usr/bin/certbot run \ + -n \ + --agree-tos \ + -m doy@tozt.net \ + --config-dir "$config_dir" \ + --cert-name <%= @primary_domain %> \ + -d <%= @primary_domain %> \ +<%- @secondary_domains.each do |domain| -%> + -d <%= domain %> \ +<%- end -%> + --nginx +fi -- cgit v1.2.3-54-g00ecf