2016-06-27 22:52:39 +02:00
|
|
|
---
|
|
|
|
|
2021-03-19 22:39:30 +01:00
|
|
|
# Use acme.sh instead of certbot because they only support installation via
|
|
|
|
# snap now.
|
2018-04-26 10:00:47 +02:00
|
|
|
- block:
|
2021-03-19 22:39:30 +01:00
|
|
|
- name: Remove certbot
|
2022-09-10 17:09:12 +02:00
|
|
|
ansible.builtin.apt:
|
2021-03-19 22:45:41 +01:00
|
|
|
name: certbot
|
|
|
|
state: absent
|
2021-03-19 22:39:30 +01:00
|
|
|
|
|
|
|
- name: Remove old certbot post and pre hooks for nginx
|
2022-09-10 17:09:12 +02:00
|
|
|
ansible.builtin.file:
|
2021-03-19 22:45:41 +01:00
|
|
|
dest: "{{ item }}"
|
|
|
|
state: absent
|
2021-03-19 22:39:30 +01:00
|
|
|
with_items:
|
|
|
|
- /etc/letsencrypt/renewal-hooks/pre/stop-nginx.sh
|
|
|
|
- /etc/letsencrypt/renewal-hooks/post/start-nginx.sh
|
|
|
|
|
2021-09-27 12:40:17 +02:00
|
|
|
- name: Check if acme.sh is installed
|
2022-09-10 17:09:12 +02:00
|
|
|
ansible.builtin.stat:
|
2021-09-27 12:40:17 +02:00
|
|
|
path: "{{ letsencrypt_acme_home }}"
|
|
|
|
register: acme_home
|
|
|
|
|
2021-03-19 22:39:30 +01:00
|
|
|
- name: Download acme.sh
|
2022-09-10 17:09:12 +02:00
|
|
|
ansible.builtin.get_url:
|
2021-03-19 22:39:30 +01:00
|
|
|
url: https://raw.githubusercontent.com/acmesh-official/acme.sh/master/acme.sh
|
2021-09-27 12:40:17 +02:00
|
|
|
dest: "{{ letsencrypt_acme_script_temp }}"
|
2021-09-07 16:10:35 +02:00
|
|
|
mode: 0700
|
2021-09-27 12:40:17 +02:00
|
|
|
register: acme_download
|
|
|
|
when: not acme_home.stat.exists
|
2021-03-19 22:39:30 +01:00
|
|
|
|
2021-09-27 10:28:02 +02:00
|
|
|
# Run the "install" for acme.sh so it creates the .acme.sh dir (currently I
|
|
|
|
# have to chdir to the /root directory where the script exists or else it
|
|
|
|
# fails. Ansible runs it, but the script can't find itself...).
|
|
|
|
- name: Install acme.sh
|
|
|
|
ansible.builtin.command:
|
2021-09-27 12:40:17 +02:00
|
|
|
cmd: "{{ letsencrypt_acme_script_temp }} --install --no-profile --no-cron"
|
2021-09-27 10:28:02 +02:00
|
|
|
creates: "{{ letsencrypt_acme_home }}/acme.sh"
|
|
|
|
chdir: /root
|
2021-09-27 12:40:17 +02:00
|
|
|
register: acme_install
|
|
|
|
when: acme_download is changed
|
|
|
|
|
|
|
|
- name: Remove temporary acme.sh script
|
2022-09-10 17:09:12 +02:00
|
|
|
ansible.builtin.file:
|
2021-09-27 12:40:17 +02:00
|
|
|
dest: "{{ letsencrypt_acme_script_temp }}"
|
|
|
|
state: absent
|
2022-09-10 22:12:49 +02:00
|
|
|
when:
|
|
|
|
- acme_install.rc is defined
|
|
|
|
- acme_install.rc == 0
|
2021-09-27 10:28:02 +02:00
|
|
|
|
|
|
|
- name: Set default certificate authority for acme.sh
|
|
|
|
ansible.builtin.command:
|
2021-09-27 12:40:17 +02:00
|
|
|
cmd: "{{ letsencrypt_acme_home }}/acme.sh --set-default-ca --server letsencrypt"
|
2021-09-27 10:28:02 +02:00
|
|
|
|
2021-03-19 22:39:30 +01:00
|
|
|
- name: Prepare Let's Encrypt well-known directory
|
2022-09-10 17:09:12 +02:00
|
|
|
ansible.builtin.file:
|
2021-03-19 22:39:30 +01:00
|
|
|
state: directory
|
|
|
|
path: /var/lib/letsencrypt/.well-known
|
|
|
|
owner: root
|
|
|
|
group: nginx
|
|
|
|
mode: g+s
|
|
|
|
|
2018-04-26 10:00:47 +02:00
|
|
|
- name: Copy systemd service to renew Let's Encrypt certs
|
2022-09-10 17:09:12 +02:00
|
|
|
ansible.builtin.template:
|
2021-03-19 22:39:30 +01:00
|
|
|
src: renew-letsencrypt.service.j2
|
|
|
|
dest: /etc/systemd/system/renew-letsencrypt.service
|
|
|
|
mode: 0644
|
|
|
|
owner: root
|
|
|
|
group: root
|
2018-04-26 10:00:47 +02:00
|
|
|
|
|
|
|
- name: Copy systemd timer to renew Let's Encrypt certs
|
2022-09-10 17:09:12 +02:00
|
|
|
ansible.builtin.copy:
|
2021-03-19 22:39:30 +01:00
|
|
|
src: renew-letsencrypt.timer
|
|
|
|
dest: /etc/systemd/system/renew-letsencrypt.timer
|
|
|
|
mode: 0644
|
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
|
|
|
|
# always issues daemon-reload just in case the service/timer changed
|
2018-04-26 10:00:47 +02:00
|
|
|
- name: Start and enable systemd timer to renew Let's Encrypt certs
|
2022-09-10 17:09:12 +02:00
|
|
|
ansible.builtin.systemd:
|
2021-03-19 22:39:30 +01:00
|
|
|
name: renew-letsencrypt.timer
|
|
|
|
state: started
|
2022-09-10 21:33:19 +02:00
|
|
|
enabled: true
|
|
|
|
daemon_reload: true
|
2020-06-06 19:38:08 +02:00
|
|
|
|
2021-09-07 16:07:33 +02:00
|
|
|
when: (ansible_distribution == 'Ubuntu' and ansible_distribution_version is version('20.04', '=='))
|
|
|
|
or (ansible_distribution == 'Debian' and ansible_distribution_version is version('11', '=='))
|
2018-04-25 19:03:32 +02:00
|
|
|
tags: letsencrypt
|
2016-06-27 22:52:39 +02:00
|
|
|
|
|
|
|
# vim: set ts=2 sw=2:
|