Files
docker-registry/provisioning/roles/registry/tasks/generate_certificates.yml
2023-12-08 21:53:09 +03:00

27 lines
825 B
YAML

---
- name: Check if certificate already exists
stat:
path: /etc/letsencrypt/live/{{ item }}/cert.pem
register: letsencrypt_certs
with_items: "{{ certbot_hosts }}"
- name: Check if server is running
wait_for:
port: 80
timeout: 1
register: port_check
ignore_errors: yes
- name: Up certbot standalone Apache
shell: "docker run -d --name apache -v /var/www/html:/usr/local/apache2/htdocs/ -p 80:80 httpd:2.4"
when: port_check.failed == true
- name: Generate new certificate
shell: "certbot certonly --noninteractive --agree-tos --email {{ certbot_email }} -d {{ item.item }}"
with_items: "{{ letsencrypt_certs.results }}"
when: not item.stat.exists
- name: Down certbot Apache
shell: "docker rm -f apache"
when: port_check.failed == true