From b4f02625cdbc1a83ca78daabe090df424aa8ee58 Mon Sep 17 00:00:00 2001 From: Michael Scherer Date: Thu, 16 Apr 2015 13:04:23 -0400 Subject: [PATCH] Add CoreOS facts detection, fix https://github.com/ansible/ansible-modules-core/issues/1000 --- lib/ansible/module_utils/facts.py | 17 ++++++++++++++++- v2/ansible/module_utils/facts.py | 17 ++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/lib/ansible/module_utils/facts.py b/lib/ansible/module_utils/facts.py index 6b817d4ebc..a9f1b17e5b 100644 --- a/lib/ansible/module_utils/facts.py +++ b/lib/ansible/module_utils/facts.py @@ -99,7 +99,8 @@ class Facts(object): ('/etc/os-release', 'SuSE'), ('/etc/gentoo-release', 'Gentoo'), ('/etc/os-release', 'Debian'), - ('/etc/lsb-release', 'Mandriva') ) + ('/etc/lsb-release', 'Mandriva'), + ('/etc/os-release', 'NA') ) SELINUX_MODE_DICT = { 1: 'enforcing', 0: 'permissive', -1: 'disabled' } # A list of dicts. If there is a platform with more than one @@ -427,6 +428,20 @@ class Facts(object): self.facts['distribution_release'] = release.groups()[0] self.facts['distribution'] = name break + elif name == 'NA': + data = get_file_content(path) + for line in data.splitlines(): + distribution = re.search("^NAME=(.*)", line) + if distribution: + self.facts['distribution'] = distribution.group(1).strip('"') + version = re.search("^VERSION=(.*)", line) + if version: + self.facts['distribution_version'] = version.group(1).strip('"') + if self.facts['distribution'].lower() == 'coreos': + data = get_file_content('/etc/coreos/update.conf') + release = re.search("^GROUP=(.*)", data) + if release: + self.facts['distribution_release'] = release.group(1).strip('"') else: self.facts['distribution'] = name machine_id = get_file_content("/var/lib/dbus/machine-id") or get_file_content("/etc/machine-id") diff --git a/v2/ansible/module_utils/facts.py b/v2/ansible/module_utils/facts.py index ae1a3094b6..5844c4f678 100644 --- a/v2/ansible/module_utils/facts.py +++ b/v2/ansible/module_utils/facts.py @@ -98,7 +98,8 @@ class Facts(object): ('/etc/os-release', 'SuSE'), ('/etc/gentoo-release', 'Gentoo'), ('/etc/os-release', 'Debian'), - ('/etc/lsb-release', 'Mandriva') ) + ('/etc/lsb-release', 'Mandriva'), + ('/etc/os-release', 'NA') ) SELINUX_MODE_DICT = { 1: 'enforcing', 0: 'permissive', -1: 'disabled' } # A list of dicts. If there is a platform with more than one @@ -386,6 +387,20 @@ class Facts(object): self.facts['distribution_release'] = release.groups()[0] self.facts['distribution'] = name break + elif name == 'NA': + data = get_file_content(path) + for line in data.splitlines(): + distribution = re.search("^NAME=(.*)", line) + if distribution: + self.facts['distribution'] = distribution.group(1).strip('"') + version = re.search("^VERSION=(.*)", line) + if version: + self.facts['distribution_version'] = version.group(1).strip('"') + if self.facts['distribution'].lower() == 'coreos': + data = get_file_content('/etc/coreos/update.conf') + release = re.search("^GROUP=(.*)", data) + if release: + self.facts['distribution_release'] = release.group(1).strip('"') else: self.facts['distribution'] = name