mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-28 23:51:23 -07:00
[stable-10] sysrc: Use shlex (#10400)
* Fix #10394 Use configparser. * Fix #10394 configparser is in Python3 only. * Fix #10394 return condition. * Fix #10394 Use ConfigParser with Python2. * Fix #10394 import configparser from ansible.module_utils.six.moves * Add changelog fragment. * Update changelogs/fragments/10400-sysrc.yml Co-authored-by: Felix Fontein <felix@fontein.de> * Fix #10394 use shlex instead of configparser. * Update fragment. * Update changelogs/fragments/10400-sysrc.yml Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/modules/sysrc.py Co-authored-by: Felix Fontein <felix@fontein.de> * Apply suggestions from code review. Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com> * Copy tests from #10417. --------- Co-authored-by: Felix Fontein <felix@fontein.de> Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
This commit is contained in:
parent
36978d71e1
commit
0be6e61b31
4 changed files with 68 additions and 4 deletions
|
@ -103,6 +103,7 @@ changed:
|
|||
"""
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from shlex import split
|
||||
import re
|
||||
|
||||
|
||||
|
@ -130,11 +131,12 @@ class Sysrc(object):
|
|||
Use this dictionary to preform the tests.
|
||||
"""
|
||||
(rc, out, err) = self.run_sysrc('-e', '-a')
|
||||
conf = dict([i.split('=', 1) for i in out.splitlines()])
|
||||
conf = dict((part.split('=', 1) for part in split(out, comments=True)))
|
||||
|
||||
if self.value is None:
|
||||
return self.name in conf
|
||||
else:
|
||||
return self.name in conf and conf[self.name] == '"%s"' % self.value
|
||||
return conf.get(self.name) == self.value
|
||||
|
||||
def contains(self):
|
||||
(rc, out, err) = self.run_sysrc('-n', self.name)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue