mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-08-02 20:24:23 -07:00
Fix cronvar crash on non existent directories
This commit is contained in:
parent
6d67546902
commit
d38835aa25
2 changed files with 19 additions and 0 deletions
|
@ -135,6 +135,9 @@ class CronVar(object):
|
||||||
self.cron_file = cron_file
|
self.cron_file = cron_file
|
||||||
else:
|
else:
|
||||||
self.cron_file = os.path.join('/etc/cron.d', cron_file)
|
self.cron_file = os.path.join('/etc/cron.d', cron_file)
|
||||||
|
parent_dir = os.path.dirname(cron_file)
|
||||||
|
if not os.path.isdir(parent_dir):
|
||||||
|
module.fail_json(msg=f"Parent directory '{parent_dir}' does not exist for cron_file: '{cron_file}'")
|
||||||
else:
|
else:
|
||||||
self.cron_file = None
|
self.cron_file = None
|
||||||
|
|
||||||
|
|
|
@ -122,3 +122,19 @@
|
||||||
- custom_varcheck1.stdout == '1'
|
- custom_varcheck1.stdout == '1'
|
||||||
- custom_varcheck2.stdout == '1'
|
- custom_varcheck2.stdout == '1'
|
||||||
- custom_varcheck3.stdout == '0'
|
- custom_varcheck3.stdout == '0'
|
||||||
|
|
||||||
|
- name: Attempt to add cron variable to non-existent parent directory
|
||||||
|
cronvar:
|
||||||
|
name: NOPARENT_VAR
|
||||||
|
value: noparentval
|
||||||
|
cron_file: /nonexistent/foo
|
||||||
|
user: root
|
||||||
|
register: invalid_directory_cronvar_result
|
||||||
|
ignore_errors: true
|
||||||
|
|
||||||
|
- name: Assert that the cronvar task failed due to invalid directory
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that:
|
||||||
|
- invalid_directory_cronvar_result is failed
|
||||||
|
- >-
|
||||||
|
"Parent directory '/nonexistent' does not exist for cron_file: '/nonexistent/foo'" == invalid_directory_cronvar_result.msg
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue