2018-11-29 17:55:28 +00:00
|
|
|
---
|
2023-07-26 14:19:27 +00:00
|
|
|
- name: Check if certificate exist
|
2021-08-24 16:18:42 +00:00
|
|
|
ansible.builtin.stat:
|
2023-07-26 14:19:27 +00:00
|
|
|
path: "/etc/letsencrypt/live/{{ item.key }}"
|
|
|
|
loop: "{{ certbot_domains | dict2items }}"
|
2022-01-03 14:27:56 +00:00
|
|
|
loop_control:
|
2023-07-26 14:19:27 +00:00
|
|
|
label: "{{ item.key }}"
|
2018-06-10 17:34:06 +00:00
|
|
|
register: st
|
|
|
|
tags: certbot
|
|
|
|
|
2023-07-26 14:19:27 +00:00
|
|
|
- name: Check if a webservice is started
|
2021-08-24 16:47:19 +00:00
|
|
|
ansible.builtin.wait_for:
|
2023-07-26 14:19:27 +00:00
|
|
|
port: "{{ certbot_port }}"
|
2021-08-24 16:47:19 +00:00
|
|
|
state: started
|
2022-01-03 14:27:56 +00:00
|
|
|
timeout: 2
|
2021-08-24 16:47:19 +00:00
|
|
|
ignore_errors: true
|
|
|
|
register: web
|
2018-06-10 17:34:06 +00:00
|
|
|
tags: certbot
|
|
|
|
|
2023-07-26 14:19:27 +00:00
|
|
|
- name: Create a new certificate # noqa no-changed-when
|
2021-08-24 16:18:42 +00:00
|
|
|
ansible.builtin.command: >
|
2022-01-03 14:27:56 +00:00
|
|
|
certbot certonly -n --agree-tos -d {{ item.item.key }} -m {{ certbot_mail }}
|
2018-11-26 17:12:43 +00:00
|
|
|
--webroot --webroot-path {{ certbot_path }} --rsa-key-size {{ certbot_key_size }}
|
2022-01-03 14:27:56 +00:00
|
|
|
--deploy-hook /etc/letsencrypt/hook-{{ item.item.key }}
|
2023-07-26 14:19:27 +00:00
|
|
|
loop: "{{ st.results }}"
|
2022-01-03 14:27:56 +00:00
|
|
|
loop_control:
|
2023-07-26 14:19:27 +00:00
|
|
|
label: "{{ item.item.key }}"
|
|
|
|
when: (certbot_role == "master" or item.item.key == ansible_fqdn) and not item.stat.exists and not web.failed
|
2018-06-10 17:34:06 +00:00
|
|
|
tags: certbot
|
|
|
|
|
2023-07-26 14:19:27 +00:00
|
|
|
- name: Create a new certificate (standalone) # noqa no-changed-when
|
2021-08-24 16:18:42 +00:00
|
|
|
ansible.builtin.command: >
|
2022-01-03 14:27:56 +00:00
|
|
|
certbot certonly -n --agree-tos -d {{ item.item.key }} -m {{ certbot_mail }}
|
|
|
|
--standalone --rsa-key-size {{ certbot_key_size }} --deploy-hook /etc/letsencrypt/hook-{{ item.item.key }}
|
|
|
|
--http-01-port {{ certbot_port }}
|
2023-07-26 14:19:27 +00:00
|
|
|
loop: "{{ st.results }}"
|
2022-01-03 14:27:56 +00:00
|
|
|
loop_control:
|
2023-07-26 14:19:27 +00:00
|
|
|
label: "{{ item.item.key }}"
|
|
|
|
when: (certbot_role == "master" or item.item.key == ansible_fqdn) and not item.stat.exists and web.failed
|
2018-06-10 17:34:06 +00:00
|
|
|
tags: certbot
|