summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRick Elrod <rick@elrod.me>2020-08-27 09:12:27 -0500
committerGitHub <noreply@github.com>2020-08-27 09:12:27 -0500
commit6b4977e3f46699fa410fe7d40c932fa622bfd494 (patch)
tree7f6bcd2429853db3fa6d94b3c8ea42c8425e0185
parentc87d3d629193a9e75aab35ae1863567b2407e6b2 (diff)
downloadansible-6b4977e3f46699fa410fe7d40c932fa622bfd494.tar.gz
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>
-rw-r--r--changelogs/fragments/fix-cron-file-regression.yaml2
-rw-r--r--lib/ansible/modules/system/cron.py1
-rw-r--r--test/integration/targets/cron/tasks/main.yml26
3 files changed, 29 insertions, 0 deletions
diff --git a/changelogs/fragments/fix-cron-file-regression.yaml b/changelogs/fragments/fix-cron-file-regression.yaml
new file mode 100644
index 0000000000..b3ab90f59c
--- /dev/null
+++ b/changelogs/fragments/fix-cron-file-regression.yaml
@@ -0,0 +1,2 @@
+bugfixes:
+ - cron - cron file should not be empty after adding var (https://github.com/ansible/ansible/pull/71207)
diff --git a/lib/ansible/modules/system/cron.py b/lib/ansible/modules/system/cron.py
index d2cab3c87c..9817bda3cd 100644
--- a/lib/ansible/modules/system/cron.py
+++ b/lib/ansible/modules/system/cron.py
@@ -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
diff --git a/test/integration/targets/cron/tasks/main.yml b/test/integration/targets/cron/tasks/main.yml
index 829b375369..3b7e30fb37 100644
--- a/test/integration/targets/cron/tasks/main.yml
+++ b/test/integration/targets/cron/tasks/main.yml
@@ -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