Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cron file regression #71207

Merged
merged 1 commit into from Aug 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions 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)
1 change: 1 addition & 0 deletions lib/ansible/modules/cron.py
Expand Up @@ -255,6 +255,7 @@ def read(self):
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
Expand Down
26 changes: 26 additions & 0 deletions test/integration/targets/cron/tasks/main.yml
Expand Up @@ -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
relrod marked this conversation as resolved.
Show resolved Hide resolved
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'
Expand Down