Backport cron module regression fix (#71244)

Change:
- Backport of #71207

Test Plan:
- CI

Tickets:
- Fixes #71213
- Fixes #71217
- Fixes #71216
- Fixes #71226
- Refs #71207

Signed-off-by: Rick Elrod <rick@elrod.me>
pull/71335/head
Rick Elrod 4 years ago committed by GitHub
parent c87d3d6291
commit 6b4977e3f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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

@ -258,6 +258,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

@ -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)
- name: Allow non-ascii chars in job (#69492)
block:
- name: Cron file creation

Loading…
Cancel
Save