Skip to content

Commit

Permalink
fix: only run commands when they are needed (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
hairmare authored Dec 18, 2024
1 parent 6d0e3be commit cbe5e09
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
26 changes: 21 additions & 5 deletions roles/certbot/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,30 @@
ansible.builtin.lineinfile:
path: "{{ certbot_certbot_sysconfig_path }}"
regexp: "^DEPLOY_HOOK="
line: DEPLOY_HOOK="--deploy-hook /usr/local/libexec/cert_sync.sh"
line: DEPLOY_HOOK="--deploy-hook {{ certbot_certsync_script_path }}"

- name: Add certificates to certbot
ansible.builtin.command: "{{ certbot_certbot_binary_path }} certonly \
--standalone \
--deploy-hook '/usr/local/libexec/cert_sync.sh'
--domains {{ item }}"
ansible.builtin.command:
argv:
- "{{ certbot_certbot_binary_path }}"
- certonly
- --standalone
- --deploy-hook
- "{{ certbot_certsync_script_path }}"
- --domains={{ item }}
creates: "{{ certbot_certificates_src }}/{{ item }}/cert.pem"
register: _certbot_certbot_certonly
changed_when: _certbot_certbot_certonly.rc
loop: "{{ certbot_certificates }}"

- name: Check ACME Account
ansible.builtin.command: "{{ certbot_certbot_binary_path }} show_account"
register: _certbot_certbot_show_account
changed_when: false
check_mode: false

- name: Update ACME account
ansible.builtin.command: "{{ certbot_certbot_binary_path }} update_account"
when: certbot_acme_account_mail not in _certbot_certbot_show_account.stdout
register: _certbot_certbot_update_account
changed_when: _certbot_certbot_update_account.rc
3 changes: 2 additions & 1 deletion roles/certbot/tests/test.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
- hosts: localhost
- name: Test certbot role
hosts: localhost
remote_user: root
roles:
- certbot

0 comments on commit cbe5e09

Please sign in to comment.