mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-06-19 23:00:22 -07:00
Parse multiple values for single key in cmdline facts (#49591)
* Facts parsing for cmdline can now handle multiple values for a single key. * Unit tests for cmdline fact parsing * Review comments Fixes: #22766 Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
parent
e98d1b1be5
commit
57d85031d7
4 changed files with 98 additions and 0 deletions
|
@ -44,6 +44,27 @@ class CmdLineFactCollector(BaseFactCollector):
|
|||
|
||||
return cmdline_dict
|
||||
|
||||
def _parse_proc_cmdline_facts(self, data):
|
||||
cmdline_dict = {}
|
||||
try:
|
||||
for piece in shlex.split(data, posix=False):
|
||||
item = piece.split('=', 1)
|
||||
if len(item) == 1:
|
||||
cmdline_dict[item[0]] = True
|
||||
else:
|
||||
if item[0] in cmdline_dict:
|
||||
if isinstance(cmdline_dict[item[0]], list):
|
||||
cmdline_dict[item[0]].append(item[1])
|
||||
else:
|
||||
new_list = [cmdline_dict[item[0]], item[1]]
|
||||
cmdline_dict[item[0]] = new_list
|
||||
else:
|
||||
cmdline_dict[item[0]] = item[1]
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
return cmdline_dict
|
||||
|
||||
def collect(self, module=None, collected_facts=None):
|
||||
cmdline_facts = {}
|
||||
|
||||
|
@ -53,4 +74,6 @@ class CmdLineFactCollector(BaseFactCollector):
|
|||
return cmdline_facts
|
||||
|
||||
cmdline_facts['cmdline'] = self._parse_proc_cmdline(data)
|
||||
cmdline_facts['proc_cmdline'] = self._parse_proc_cmdline_facts(data)
|
||||
|
||||
return cmdline_facts
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue