[PR #10461/cc13f42b backport][stable-10] Fix cronvar crash when parent dir of cron_file is missing (#10473)

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



* Update plugins/modules/cronvar.py



---------


(cherry picked from commit cc13f42be4)

Co-authored-by: Giorgos Drosos <56369797+gdrosos@users.noreply.github.com>
Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
patchback[bot] 2025-07-27 12:13:23 +02:00 committed by GitHub
commit e2573de08d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 21 additions and 0 deletions

View file

@ -135,6 +135,9 @@ class CronVar(object):
self.cron_file = cron_file
else:
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:
self.cron_file = None