diff --git a/lib/ansible/module_utils/facts/system/distribution.py b/lib/ansible/module_utils/facts/system/distribution.py index 9bb0ecc890e..8de264efaf1 100644 --- a/lib/ansible/module_utils/facts/system/distribution.py +++ b/lib/ansible/module_utils/facts/system/distribution.py @@ -94,6 +94,8 @@ class DistributionFiles: 'Archlinux': 'Arch Linux' } + STRIP_QUOTES = r'\'\"\\' + def __init__(self, module): self.module = module @@ -110,6 +112,7 @@ class DistributionFiles: def _parse_dist_file(self, name, dist_file_content, path, collected_facts): dist_file_dict = {} + dist_file_content = dist_file_content.strip(DistributionFiles.STRIP_QUOTES) if name in self.SEARCH_STRING: # look for the distribution string in the data and replace according to RELEASE_NAME_MAP # only the distribution name is set, the version is assumed to be correct from distro.linux_distribution() diff --git a/lib/ansible/module_utils/facts/system/lsb.py b/lib/ansible/module_utils/facts/system/lsb.py index c6ee553a80d..596e7256f8e 100644 --- a/lib/ansible/module_utils/facts/system/lsb.py +++ b/lib/ansible/module_utils/facts/system/lsb.py @@ -27,6 +27,7 @@ from ansible.module_utils.facts.collector import BaseFactCollector class LSBFactCollector(BaseFactCollector): name = 'lsb' _fact_ids = set() + STRIP_QUOTES = r'\'\"\\' def _lsb_release_bin(self, lsb_path, module): lsb_facts = {} @@ -97,5 +98,9 @@ class LSBFactCollector(BaseFactCollector): if lsb_facts and 'release' in lsb_facts: lsb_facts['major_release'] = lsb_facts['release'].split('.')[0] + for k, v in lsb_facts.items(): + if v: + lsb_facts[k] = v.strip(LSBFactCollector.STRIP_QUOTES) + facts_dict['lsb'] = lsb_facts return facts_dict diff --git a/test/units/module_utils/facts/system/test_lsb.py b/test/units/module_utils/facts/system/test_lsb.py index dd5188b2fdd..1a090bf9c34 100644 --- a/test/units/module_utils/facts/system/test_lsb.py +++ b/test/units/module_utils/facts/system/test_lsb.py @@ -88,7 +88,7 @@ class TestLSBFacts(BaseFactsTest): self.assertIsInstance(facts_dict, dict) self.assertEqual(facts_dict['lsb']['release'], '14.04') self.assertEqual(facts_dict['lsb']['id'], 'Ubuntu') - self.assertEqual(facts_dict['lsb']['description'], '"Ubuntu 14.04.3 LTS"') + self.assertEqual(facts_dict['lsb']['description'], 'Ubuntu 14.04.3 LTS') self.assertEqual(facts_dict['lsb']['codename'], 'trusty') def test_etc_lsb_release_no_decimal_release(self): @@ -104,5 +104,5 @@ class TestLSBFacts(BaseFactsTest): self.assertIsInstance(facts_dict, dict) self.assertEqual(facts_dict['lsb']['release'], '11') self.assertEqual(facts_dict['lsb']['id'], 'AwesomeOS') - self.assertEqual(facts_dict['lsb']['description'], '"AwesomeÖS 11"') + self.assertEqual(facts_dict['lsb']['description'], 'AwesomeÖS 11') self.assertEqual(facts_dict['lsb']['codename'], 'stonehenge')