Update crontab_renew.yml
This commit is contained in:
+10
-23
@@ -4,29 +4,16 @@
|
|||||||
become: true
|
become: true
|
||||||
|
|
||||||
tasks:
|
tasks:
|
||||||
- name: Read current root crontab
|
- name: Check if certbot line exists and is uncommented
|
||||||
ansible.builtin.command: crontab -l -u root
|
ansible.builtin.shell: |
|
||||||
register: root_crontab
|
crontab -l -u root 2>/dev/null | grep -q '^[^#].*certbot renew -q --force-renewal'
|
||||||
|
register: certbot_line
|
||||||
changed_when: false
|
changed_when: false
|
||||||
failed_when: root_crontab.rc not in [0, 1]
|
failed_when: false
|
||||||
|
|
||||||
- name: Comment out certbot renew line
|
- name: Comment out certbot renew line
|
||||||
ansible.builtin.copy:
|
ansible.builtin.shell: |
|
||||||
content: >-
|
crontab -l -u root 2>/dev/null | \
|
||||||
{{
|
sed 's|^\([^#].*certbot renew -q --force-renewal.*\)|#\1|' | \
|
||||||
root_crontab.stdout_lines
|
crontab -u root -
|
||||||
| map('regex_replace', '^(?!#)(.*certbot renew -q --force-renewal.*)$', '#\1')
|
when: certbot_line.rc == 0
|
||||||
| 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
|
|
||||||
Reference in New Issue
Block a user