42 lines
1 KiB
YAML
42 lines
1 KiB
YAML
---
|
|
- name: Install certbot and nginx plugin
|
|
apt:
|
|
update_cache: true
|
|
name:
|
|
- certbot
|
|
- python3-certbot-nginx
|
|
register: pkg_result
|
|
retries: 3
|
|
until: pkg_result is succeeded
|
|
|
|
- name: Check if certificate already exists.
|
|
stat:
|
|
path: "/etc/letsencrypt/live/{{ certbot.certname }}/cert.pem"
|
|
register: letsencrypt_cert
|
|
|
|
- name: Create /etc/letsencrypt/conf.d
|
|
file:
|
|
path: /etc/letsencrypt/conf.d
|
|
state: directory
|
|
mode: 0755
|
|
|
|
- name: Add Certbot configuration
|
|
template:
|
|
src: "letsencrypt/conf.d/certname.ini.j2"
|
|
dest: "/etc/letsencrypt/conf.d/{{ certbot.certname }}.ini"
|
|
mode: 0644
|
|
|
|
- name: Stop services to allow certbot to generate a cert.
|
|
service:
|
|
name: nginx
|
|
state: stopped
|
|
|
|
- name: Generate new certificate if one doesn't exist.
|
|
shell: "certbot certonly --non-interactive --config /etc/letsencrypt/conf.d/{{ certbot.certname }}.ini"
|
|
when: letsencrypt_cert.stat.exists == False
|
|
|
|
- name: Restart services to allow certbot to generate a cert.
|
|
service:
|
|
name: nginx
|
|
state: started
|
|
|