Fix cron file regression (#71207)

This commit is contained in:
Florent PIGOUT 2020-08-12 21:04:29 +02:00 committed by GitHub
parent 888be697cb
commit 336c176ebc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 0 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- cron - cron file should not be empty after adding var (https://github.com/ansible/ansible/pull/71207)

View file

@ -255,6 +255,7 @@ class CronTab(object):
try:
f = open(self.b_cron_file, 'rb')
self.n_existing = to_native(f.read(), errors='surrogate_or_strict')
self.lines = self.n_existing.splitlines()
f.close()
except IOError:
# cron file does not exist

View file

@ -100,6 +100,32 @@
- assert:
that: remove_cron_file is not changed
- name: Non regression test - cron file should not be empty after adding var (#71207)
when: ansible_distribution != 'Alpine'
block:
- name: Cron file creation
cron:
cron_file: cron_filename
name: "simple cron job"
job: 'echo "_o/"'
user: root
- name: Add var to the cron file
cron:
cron_file: cron_filename
env: yes
name: FOO
value: bar
user: root
- name: "Ensure cron_file still contains job string"
replace:
path: /etc/cron.d/cron_filename
regexp: "_o/"
replace: "OK"
register: find_chars
failed_when: (find_chars is not changed) or (find_chars is failed)
# BusyBox does not have /etc/cron.d
- name: Removing a cron file when the name is specified is allowed (#57471)
when: ansible_distribution != 'Alpine'