From 07c19bf1b7c081a94ca887a6ed05901830a5fb3a Mon Sep 17 00:00:00 2001 From: Vladimir Botka Date: Sun, 13 Jul 2025 21:30:01 +0200 Subject: [PATCH] Fix #10394 Use ConfigParser with Python2. --- plugins/modules/sysrc.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/plugins/modules/sysrc.py b/plugins/modules/sysrc.py index 3b44ca0fd0..bfa41b70b6 100644 --- a/plugins/modules/sysrc.py +++ b/plugins/modules/sysrc.py @@ -105,7 +105,10 @@ changed: from ansible.module_utils.basic import AnsibleModule import re import sys -if sys.version_info > (3, 5): + +if sys.version_info < (3, 0): + from ConfigParser import ConfigParser +else: from configparser import ConfigParser @@ -133,13 +136,9 @@ class Sysrc(object): Use this dictionary to preform the tests. """ (rc, out, err) = self.run_sysrc('-e', '-a') - - if sys.version_info > (3, 5): - parser = ConfigParser() - parser.read_string('[top]\n' + out) # Add faked top section - conf = {k: parser['top'][k] for k in parser['top']} - else: - conf = dict([i.split('=', 1) for i in out.splitlines()]) + parser = ConfigParser() + parser.read_string('[top]\n' + out) # Add faked top section + conf = {k: parser['top'][k] for k in parser['top']} if self.value is None: return self.name in conf