diff --git a/roles/nginx/files/start-nginx.sh b/roles/nginx/files/start-nginx.sh new file mode 100755 index 0000000..d8210a4 --- /dev/null +++ b/roles/nginx/files/start-nginx.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +/bin/systemctl start nginx diff --git a/roles/nginx/files/stop-nginx.sh b/roles/nginx/files/stop-nginx.sh new file mode 100755 index 0000000..3625e47 --- /dev/null +++ b/roles/nginx/files/stop-nginx.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +/bin/systemctl stop nginx diff --git a/roles/nginx/tasks/letsencrypt.yml b/roles/nginx/tasks/letsencrypt.yml index f3f1c5d..9f0a1b4 100644 --- a/roles/nginx/tasks/letsencrypt.yml +++ b/roles/nginx/tasks/letsencrypt.yml @@ -216,8 +216,16 @@ # On Ubuntu 20.04 it is no longer recommended/supported to use the standalone # certbot-auto so I guess we need to use the one from the repositories. -- name: Install certbot (Ubuntu 20.04) - apt: name=certbot state=present update_cache=yes +- block: + - name: Install certbot (Ubuntu 20.04) + apt: name=certbot state=present update_cache=yes + + - name: Copy certbot post and pre hooks for nginx + copy: src={{ item.src }} dest={{ item.dest }} owner=root group=root mode=0755 + with_items: + - { src: 'stop-nginx.sh', dest: '/etc/letsencrypt/renewal-hooks/post/stop-nginx.sh' } + - { src: 'start-nginx.sh', dest: '/etc/letsencrypt/renewal-hooks/post/start-nginx.sh' } + when: ansible_distribution == 'Ubuntu' and ansible_distribution_version is version('20.04', '==') tags: letsencrypt