diff options
author | Matt Martz <matt@sivel.net> | 2016-01-20 13:08:16 -0600 |
---|---|---|
committer | Matt Martz <matt@sivel.net> | 2016-01-20 13:08:16 -0600 |
commit | d49b11e9962df4bde4b8f3d61029305af4115748 (patch) | |
tree | 0be69f719c69272177343037f618d93539132b7e | |
parent | 1894a83772bb9f0f985f3f3438700d56cc95b845 (diff) | |
download | ansible-d49b11e9962df4bde4b8f3d61029305af4115748.tar.gz |
Only use os.path.basename if get_file_content returned a value, and ensure that service_mgr has line endings stripped. Fixes #14026
-rw-r--r-- | lib/ansible/module_utils/facts.py | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/lib/ansible/module_utils/facts.py b/lib/ansible/module_utils/facts.py index 3cb66a83e8..18fa26332b 100644 --- a/lib/ansible/module_utils/facts.py +++ b/lib/ansible/module_utils/facts.py @@ -559,9 +559,11 @@ class Facts(object): # also other OSs other than linux might need to check across several possible candidates # try various forms of querying pid 1 - proc_1 = os.path.basename(get_file_content('/proc/1/comm')) + proc_1 = get_file_content('/proc/1/comm') if proc_1 is None: rc, proc_1, err = module.run_command("ps -p 1 -o comm|tail -n 1", use_unsafe_shell=True) + else: + proc_1 = os.path.basename(proc_1) if proc_1 == 'init' or proc_1.endswith('sh'): # many systems return init, so this cannot be trusted, if it ends in 'sh' it probalby is a shell in a container @@ -569,7 +571,7 @@ class Facts(object): # if not init/None it should be an identifiable or custom init, so we are done! if proc_1 is not None: - self.facts['service_mgr'] = proc_1 + self.facts['service_mgr'] = proc_1.strip() # start with the easy ones elif self.facts['distribution'] == 'MacOSX': |