mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-08-03 04:34:24 -07:00
Fix #10394 configparser is in Python3 only.
This commit is contained in:
parent
43cc345e33
commit
bb7588df0b
1 changed files with 14 additions and 6 deletions
|
@ -103,8 +103,10 @@ changed:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
from configparser import ConfigParser
|
|
||||||
import re
|
import re
|
||||||
|
import sys
|
||||||
|
if sys.version_info > (3, 5):
|
||||||
|
from configparser import ConfigParser
|
||||||
|
|
||||||
|
|
||||||
class Sysrc(object):
|
class Sysrc(object):
|
||||||
|
@ -131,12 +133,18 @@ class Sysrc(object):
|
||||||
Use this dictionary to preform the tests.
|
Use this dictionary to preform the tests.
|
||||||
"""
|
"""
|
||||||
(rc, out, err) = self.run_sysrc('-e', '-a')
|
(rc, out, err) = self.run_sysrc('-e', '-a')
|
||||||
conf = ConfigParser()
|
|
||||||
conf.read_string('[top]\n' + out) # Add faked top section
|
if sys.version_info > (3, 5):
|
||||||
if self.value is None:
|
parser = ConfigParser()
|
||||||
return self.name in conf['top']
|
parser.read_string('[top]\n' + out) # Add faked top section
|
||||||
|
conf = {k: parser['top'][k] for k in parser['top']}
|
||||||
else:
|
else:
|
||||||
return conf['top'][self.name] == '"%s"' % self.value
|
conf = dict([i.split('=', 1) for i in out.splitlines()])
|
||||||
|
|
||||||
|
if self.value is None:
|
||||||
|
return self.name in conf
|
||||||
|
else:
|
||||||
|
return conf[self.name] == '"%s"' % self.value
|
||||||
|
|
||||||
def contains(self):
|
def contains(self):
|
||||||
(rc, out, err) = self.run_sysrc('-n', self.name)
|
(rc, out, err) = self.run_sysrc('-n', self.name)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue