From 0130e9bab2dc4021c2e60002fb7b06ff683832af Mon Sep 17 00:00:00 2001 From: "Karl A. Grindley" Date: Tue, 20 Feb 2024 08:28:02 -0500 Subject: [PATCH] add error handling when parsing values in ini files https://github.com/ansible/ansible/issues/82717 --- lib/ansible/module_utils/facts/system/local.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/ansible/module_utils/facts/system/local.py b/lib/ansible/module_utils/facts/system/local.py index 3d656f5a345..d9d627d299f 100644 --- a/lib/ansible/module_utils/facts/system/local.py +++ b/lib/ansible/module_utils/facts/system/local.py @@ -104,8 +104,14 @@ class LocalFactCollector(BaseFactCollector): if sect not in fact: fact[sect] = {} for opt in cp.options(sect): - val = cp.get(sect, opt) - fact[sect][opt] = val + try: + val = cp.get(sect, opt) + except configparser.Error as ex: + fact = "error loading facts as ini - please check content: %s (%s)" % (fn, ex) + module.warn(fact) + continue + else: + fact[sect][opt] = val except Exception as e: fact = "Failed to convert (%s) to JSON: %s" % (fn, to_text(e)) module.warn(fact)