2020-01-14 10:55:56 +00:00
|
|
|
---
|
2021-09-01 20:30:41 +00:00
|
|
|
- name: Create Let's Encrypt system group
|
|
|
|
group:
|
|
|
|
name: '{{ common__certbot__group }}'
|
|
|
|
system: true
|
|
|
|
|
2020-01-14 10:55:56 +00:00
|
|
|
- name: Install Certbot
|
2020-01-14 12:59:51 +00:00
|
|
|
apt:
|
|
|
|
name: certbot
|
2020-01-14 10:55:56 +00:00
|
|
|
|
2021-09-01 20:30:41 +00:00
|
|
|
- name: Create directories for Let's Encrypt configuration
|
2020-01-14 10:55:56 +00:00
|
|
|
file:
|
|
|
|
state: directory
|
2021-09-01 20:30:41 +00:00
|
|
|
path: '{{ item }}'
|
2020-01-14 10:55:56 +00:00
|
|
|
mode: 'u=rwx,g=rx,o=rx'
|
|
|
|
owner: root
|
|
|
|
group: root
|
2021-09-01 20:30:41 +00:00
|
|
|
with_items:
|
|
|
|
- '{{ common__certbot__conf_dir }}'
|
|
|
|
- '{{ common__certbot__archive_dir }}'
|
|
|
|
- '{{ common__certbot__archive_dir }}/{{ common__certbot__cert_name }}'
|
|
|
|
- '{{ common__certbot__live_dir }}'
|
|
|
|
- '{{ common__certbot__live_dir }}/{{ common__certbot__cert_name }}'
|
2020-01-14 10:55:56 +00:00
|
|
|
|
|
|
|
- name: Install Let's Encrypt config
|
|
|
|
template:
|
|
|
|
src: templates/certbot/cli.ini
|
|
|
|
dest: '{{ common__certbot__conf_cli }}'
|
|
|
|
mode: 'u=rw,g=r,o=r'
|
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
|
|
|
|
- name: Install Nginx SSL options
|
2020-02-06 12:25:21 +00:00
|
|
|
template:
|
|
|
|
src: templates/certbot/options-ssl-nginx.conf
|
2020-01-14 10:55:56 +00:00
|
|
|
dest: '{{ common__certbot__conf_nginx }}'
|
|
|
|
mode: 'u=rw,g=r,o=r'
|
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
|
|
|
|
- name: Obtain Let's Encrypt certificate
|
2020-01-14 12:59:51 +00:00
|
|
|
command: 'certbot certonly'
|
2020-01-14 10:55:56 +00:00
|
|
|
register: common__certbot__result
|
2020-01-14 12:05:26 +00:00
|
|
|
when: common__certbot__run|bool
|
2020-01-14 10:55:56 +00:00
|
|
|
changed_when: >-
|
|
|
|
common__certbot__result.stdout is
|
|
|
|
not search('Certificate not yet due for renewal; no action taken.')
|
2021-09-01 20:30:41 +00:00
|
|
|
|
|
|
|
- name: Find Let's Encrypt certificates and chains
|
|
|
|
register: certs_and_chains
|
|
|
|
find:
|
|
|
|
paths: '{{ common__certbot__archive_dir }}/{{ common__certbot__cert_name }}'
|
|
|
|
patterns:
|
|
|
|
- 'cert*.pem'
|
|
|
|
- 'chain*.pem'
|
|
|
|
- 'fullchain*.pem'
|
|
|
|
|
|
|
|
- name: Find Let's Encrypt private keys
|
|
|
|
register: privkeys
|
|
|
|
find:
|
|
|
|
paths: '{{ common__certbot__archive_dir }}/{{ common__certbot__cert_name }}'
|
|
|
|
patterns: 'privkey*.pem'
|
|
|
|
|
|
|
|
- name: Display Let's Encrypt certificates and chains
|
|
|
|
debug:
|
|
|
|
msg: "{{ certs_and_chains.files | map(attribute='path') | list }}"
|
|
|
|
|
|
|
|
- name: Display Let's Encrypt private keys
|
|
|
|
debug:
|
|
|
|
msg: "{{ privkeys.files | map(attribute='path') | list }}"
|
|
|
|
|
|
|
|
- name: Change group of Let's Encrypt certificates and chains
|
|
|
|
file:
|
|
|
|
path: '{{ item }}'
|
|
|
|
mode: 'u=rw,g=r,o=r'
|
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
with_items: "{{ certs_and_chains.files | map(attribute='path') | list }}"
|
|
|
|
|
|
|
|
- name: Change group of Let's Encrypt private keys
|
|
|
|
file:
|
|
|
|
path: '{{ item }}'
|
|
|
|
mode: 'u=rw,g=r,o='
|
|
|
|
owner: root
|
|
|
|
group: '{{ common__certbot__group }}'
|
|
|
|
with_items: "{{ privkeys.files | map(attribute='path') | list }}"
|