Update crontab_renew.yml

This commit is contained in:
2026-04-29 09:46:03 +01:00
parent fb92d5deda
commit 741f4f9fd2
+10 -23
View File
@@ -4,29 +4,16 @@
become: true
tasks:
- name: Read current root crontab
ansible.builtin.command: crontab -l -u root
register: root_crontab
- name: Check if certbot line exists and is uncommented
ansible.builtin.shell: |
crontab -l -u root 2>/dev/null | grep -q '^[^#].*certbot renew -q --force-renewal'
register: certbot_line
changed_when: false
failed_when: root_crontab.rc not in [0, 1]
failed_when: false
- name: Comment out certbot renew line
ansible.builtin.copy:
content: >-
{{
root_crontab.stdout_lines
| map('regex_replace', '^(?!#)(.*certbot renew -q --force-renewal.*)$', '#\1')
| join('\n')
}}{{ '\n' }}
dest: /tmp/root_crontab_modified
mode: '0600'
when: root_crontab.rc == 0
- name: Install modified crontab
ansible.builtin.command: crontab -u root /tmp/root_crontab_modified
when: root_crontab.rc == 0
- name: Remove temporary crontab file
ansible.builtin.file:
path: /tmp/root_crontab_modified
state: absent
ansible.builtin.shell: |
crontab -l -u root 2>/dev/null | \
sed 's|^\([^#].*certbot renew -q --force-renewal.*\)|#\1|' | \
crontab -u root -
when: certbot_line.rc == 0