Removing a cron file when the 'name' parameter is specified is now allowed (#57471). Added integration tests to validate new behavior. (#65640)

Also added user input validation to return a clear error when deleting an environment variables without specifying a name.
This commit is contained in:
Emmanuel MICKIEWICZ 2020-02-15 15:52:36 +01:00 committed by GitHub
parent fe6848badd
commit 8647d0a873
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 1 deletions

View file

@ -642,6 +642,9 @@ def main():
# --- user input validation ---
if env and not name:
module.fail_json(msg="You must specify 'name' while working with environment variables (env=yes)")
if (special_time or reboot) and \
(True in [(x != '*') for x in [minute, hour, day, month, weekday]]):
module.fail_json(msg="You must specify time and date fields or special time.")
@ -668,7 +671,7 @@ def main():
(backuph, backup_file) = tempfile.mkstemp(prefix='crontab')
crontab.write(backup_file)
if crontab.cron_file and not name and not do_install:
if crontab.cron_file and not do_install:
if module._diff:
diff['after'] = ''
diff['after_header'] = '/dev/null'

View file

@ -99,3 +99,26 @@
- assert:
that: remove_cron_file is not changed
- name: Removing a cron file when the name is specified is allowed (#57471)
block:
- name: Cron file creation
cron:
cron_file: cron_filename
name: "integration test cron"
job: 'ls'
user: root
- name: Cron file deletion
cron:
cron_file: cron_filename
name: "integration test cron"
state: absent
- name: Check file succesfull deletion
stat:
path: /etc/cron.d/cron_filename
register: cron_file_stats
- assert:
that: not cron_file_stats.stat.exists