diff --git a/crontab_renew.yml b/crontab_renew.yml index 66eaf33..18f0b9c 100644 --- a/crontab_renew.yml +++ b/crontab_renew.yml @@ -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 \ No newline at end of file + 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 \ No newline at end of file