use cloudflare memes

This commit is contained in:
Torma Kristóf 2023-03-05 19:48:09 +01:00
parent 6800a75f86
commit 3a4e849592
4 changed files with 18 additions and 5 deletions

View File

@ -69,4 +69,4 @@ http {
try_files $uri $uri/ =404; try_files $uri $uri/ =404;
} }
} }
} }

View File

@ -12,7 +12,7 @@
name: name:
- nginx - nginx
- python3-certbot - python3-certbot
- python3-certbot-nginx - python3-certbot-dns-cloudflare
- name: Copy default nginx config - name: Copy default nginx config
ansible.builtin.copy: ansible.builtin.copy:
@ -28,14 +28,24 @@
state: restarted state: restarted
enabled: yes enabled: yes
- name: "Get Cloudflare token from local environment variable"
ansible.builtin.set_fact:
cloudflare_token: "{{ lookup('env', 'CLOUDFLARE_TOKEN') }}"
delegate_to: localhost
- name: "Render Cloudflare Certbot plugin configuration"
ansible.builtin.template:
src: cf-creds.ini
dest: /root/cf-creds.ini
- name: Generate certificate for all server instances - name: Generate certificate for all server instances
ansible.builtin.command: ansible.builtin.command:
cmd: certbot certonly --non-interactive --agree-tos -m tormakristof@tormakristof.eu --nginx -d {{item.domain}} cmd: certbot certonly --non-interactive --agree-tos -m iam@tormakristof.eu --dns-cloudflare --dns-cloudflare-credentials /root/cf-creds.ini -d {{item.domain}}
with_items: "{{ webserver }}" with_items: "{{ webserver }}"
- name: "Generate certbot script" - name: "Generate certbot script"
ansible.builtin.template: ansible.builtin.template:
src: certbot.sh src: certbot.shb
dest: /etc/cron.weekly/certbot dest: /etc/cron.weekly/certbot
owner: root owner: root
group: root group: root

View File

@ -1,5 +1,5 @@
#!/bin/bash #!/bin/bash
# {{ansible_managed}} # {{ansible_managed}}
{% for server in webserver %} {% for server in webserver %}
certbot renew --nginx --cert-name {{ server.domain }} certbot renew --dns-cloudflare --dns-cloudflare-credentials /root/cf-creds.ini 10 --cert-name {{ server.domain }}
{% endfor %} {% endfor %}

View File

@ -0,0 +1,3 @@
# Cloudflare API token used by Certbot
# {{ ansible_managed }}
dns_cloudflare_api_token = {{ cloudflare_token }}