Also detect crontab which only contains whitespace as empty.

pull/74497/head
Fabian Klemp 5 years ago
parent 1e37fa86b4
commit 4b69c8f501

@ -283,7 +283,10 @@ class CronTab(object):
if len(self.lines) == 0:
return True
else:
return False
for line in self.lines:
if line.strip():
return False
return True
def write(self, backup_file=None):
"""

@ -160,6 +160,42 @@
- assert:
that: not cron_file_stats.stat.exists
# BusyBox does not have /etc/cron.d
- name: Removing a cron file, which contains only whitespace
when: ansible_distribution != 'Alpine'
block:
- name: Check file does not exist
stat:
path: /etc/cron.d/cron_remove_whitespace
register: cron_file_stats
- assert:
that: not cron_file_stats.stat.exists
- name: Cron file creation
cron:
cron_file: cron_remove_whitespace
name: "integration test cron"
job: 'ls'
user: root
- name: Add whitespace to cron file
shell: 'printf "\n \n\t\n" >> /etc/cron.d/cron_remove_whitespace'
- name: Cron file deletion
cron:
cron_file: cron_remove_whitespace
name: "integration test cron"
state: absent
- name: Check file succesfull deletion
stat:
path: /etc/cron.d/cron_remove_whitespace
register: cron_file_stats
- assert:
that: not cron_file_stats.stat.exists
- name: System cron tab does not get removed
block:
- name: Add cron job

Loading…
Cancel
Save