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:
parent
fe6848badd
commit
8647d0a873
2 changed files with 27 additions and 1 deletions
|
@ -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'
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue