Fix cron file regression (#71207) (#71243)

Co-authored-by: Florent PIGOUT <toopy@users.noreply.github.com>
This commit is contained in:
Rick Elrod 2020-08-27 12:54:15 -05:00 committed by GitHub
parent 7662568bd8
commit 7b3d2a00a0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 30 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,33 @@
- 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)
block:
- name: Cron file creation