mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-06 13:22:48 +00:00
Cmdline fact uefi 23647 (#25446)
* Fix ansible_cmdline initrd fact for UEFI UEFI cmdline paths use \ path sep which would get munged by cmdline fact collection. * Make CmdLineFactCollector easier to test extract the parsing of the /proc/cmdline content to _parse_proc_cmdline() add a wrapper method for get_file_content _get_proc_cmdline() Add unit tests of _parse_proc_cmdline based on examples from issue #23647 Fixes #23647
This commit is contained in:
@@ -27,24 +27,30 @@ class CmdLineFactCollector(BaseFactCollector):
|
||||
name = 'cmdline'
|
||||
_fact_ids = set()
|
||||
|
||||
def _get_proc_cmdline(self):
|
||||
return get_file_content('/proc/cmdline')
|
||||
|
||||
def _parse_proc_cmdline(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:
|
||||
cmdline_dict[item[0]] = item[1]
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
return cmdline_dict
|
||||
|
||||
def collect(self, module=None, collected_facts=None):
|
||||
cmdline_facts = {}
|
||||
|
||||
data = get_file_content('/proc/cmdline')
|
||||
data = self._get_proc_cmdline()
|
||||
|
||||
if not data:
|
||||
return cmdline_facts
|
||||
|
||||
cmdline_facts['cmdline'] = {}
|
||||
|
||||
try:
|
||||
for piece in shlex.split(data):
|
||||
item = piece.split('=', 1)
|
||||
if len(item) == 1:
|
||||
cmdline_facts['cmdline'][item[0]] = True
|
||||
else:
|
||||
cmdline_facts['cmdline'][item[0]] = item[1]
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
cmdline_facts['cmdline'] = self._parse_proc_cmdline(data)
|
||||
return cmdline_facts
|
||||
|
||||
Reference in New Issue
Block a user