From a409b985e8eaed077c1f1bafd758221c493716ee Mon Sep 17 00:00:00 2001 From: Matt Spencer Date: Wed, 2 Dec 2026 12:13:53 +0000 Subject: [PATCH] Use vault secret for Cloudflare token and fail if empty An unset env var led to an empty cloudflare.ini, breaking certbot renewal. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- frontend.yaml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/frontend.yaml b/frontend.yaml index 31327da..43ad4fd 100755 --- a/frontend.yaml +++ b/frontend.yaml @@ -9,7 +9,7 @@ certbot_dir: "{{ ansible_env.HOME }}/.local/share/certbot" certbot_config_dir: "{{ ansible_env.HOME }}/.config/letsencrypt" - cloudflare_api_token: "{{ lookup('env', 'CLOUDFLARE_API_TOKEN') }}" + cloudflare_api_token: "{{ secrets.CLOUDFLARE_API_TOKEN | default(lookup('env', 'CLOUDFLARE_API_TOKEN')) }}" certbot_admin_email: "{{ lookup('env', 'CERTBOT_ADMIN_EMAIL') }}" roles: @@ -41,6 +41,11 @@ - "{{ certbot_config_dir }}/work" - "{{ certbot_config_dir }}/logs" + - name: Ensure Cloudflare API token is set + ansible.builtin.assert: + that: cloudflare_api_token | length > 0 + fail_msg: CLOUDFLARE_API_TOKEN is empty; certbot renewal would fail. Pass -e @secrets.enc or set the env var. + - name: Deploy Cloudflare API credentials file ansible.builtin.copy: dest: "{{ certbot_config_dir }}/cloudflare.ini"