mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-28 07:31:23 -07:00
Fix cronvar crash when parent dir of cron_file is missing (#10461)
* Fix cronvar crash on non existent directories * Update changelog * Fix small variable bug * Fix trailing witespace * Fix CI issues * Update changelogs/fragments/10461-cronvar-non-existent-dir-crash-fix.yml Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/modules/cronvar.py Co-authored-by: Felix Fontein <felix@fontein.de> --------- Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
parent
ee7830667a
commit
cc13f42be4
3 changed files with 21 additions and 0 deletions
|
@ -0,0 +1,2 @@
|
||||||
|
bugfixes:
|
||||||
|
- "cronvar - fix crash on missing ``cron_file`` parent directories (https://github.com/ansible-collections/community.general/issues/10460, https://github.com/ansible-collections/community.general/pull/10461)."
|
|
@ -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(self.cron_file)
|
||||||
|
if parent_dir and not os.path.isdir(parent_dir):
|
||||||
|
module.fail_json(msg="Parent directory '{}' does not exist for cron_file: '{}'".format(parent_dir, 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