diff options
author | Dongsu Park <dongsu@kinvolk.io> | 2020-06-02 15:11:53 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-02 15:11:53 +0200 |
commit | 598e3392a9597f0214d68882da4f4ca07314ce41 (patch) | |
tree | 066c1bf9613c953ebfdb038bed192f913c8cd6c4 | |
parent | Update 2.10 roadmap dates (#69771) (diff) | |
download | ansible-598e3392a9597f0214d68882da4f4ca07314ce41.tar.xz ansible-598e3392a9597f0214d68882da4f4ca07314ce41.zip |
Discover Flatcar Linux properly for hostname (#69627)
To avoid issues with Flatcar Container Linux being unable to be found,
detect Flatcar distro name especially for hostname, just like CoreOS
Container Linux was supported.
See also https://github.com/ansible/ansible/issues/69516
7 files changed, 56 insertions, 0 deletions
diff --git a/changelogs/fragments/69516_flatcar_distribution.yml b/changelogs/fragments/69516_flatcar_distribution.yml new file mode 100644 index 0000000000..143a3307e6 --- /dev/null +++ b/changelogs/fragments/69516_flatcar_distribution.yml @@ -0,0 +1,2 @@ +bugfixes: + - Added support for Flatcar Container Linux in distribution and hostname modules. (https://github.com/ansible/ansible/pull/69627) diff --git a/hacking/tests/gen_distribution_version_testcase.py b/hacking/tests/gen_distribution_version_testcase.py index 83c0b40db4..21c51d358e 100755 --- a/hacking/tests/gen_distribution_version_testcase.py +++ b/hacking/tests/gen_distribution_version_testcase.py @@ -37,6 +37,7 @@ filelist = [ '/etc/altlinux-release', '/etc/os-release', '/etc/coreos/update.conf', + '/etc/flatcar/update.conf', '/usr/lib/os-release', ] diff --git a/lib/ansible/module_utils/facts/system/distribution.py b/lib/ansible/module_utils/facts/system/distribution.py index 233a99aa85..1ddaae8c11 100644 --- a/lib/ansible/module_utils/facts/system/distribution.py +++ b/lib/ansible/module_utils/facts/system/distribution.py @@ -71,6 +71,7 @@ class DistributionFiles: {'path': '/etc/sourcemage-release', 'name': 'SMGL'}, {'path': '/usr/lib/os-release', 'name': 'ClearLinux'}, {'path': '/etc/coreos/update.conf', 'name': 'Coreos'}, + {'path': '/etc/flatcar/update.conf', 'name': 'Flatcar'}, {'path': '/etc/os-release', 'name': 'NA'}, ) @@ -402,6 +403,21 @@ class DistributionFiles: return True, coreos_facts + def parse_distribution_file_Flatcar(self, name, data, path, collected_facts): + flatcar_facts = {} + distro = get_distribution() + + if distro.lower() == 'flatcar': + if not data: + return False, flatcar_facts + release = re.search("^GROUP=(.*)", data) + if release: + flatcar_facts['distribution_release'] = release.group(1).strip('"') + else: + return False, flatcar_facts + + return True, flatcar_facts + def parse_distribution_file_ClearLinux(self, name, data, path, collected_facts): clear_facts = {} if "clearlinux" not in name.lower(): @@ -453,6 +469,7 @@ class Distribution(object): {'path': '/etc/sourcemage-release', 'name': 'SMGL'}, {'path': '/usr/lib/os-release', 'name': 'ClearLinux'}, {'path': '/etc/coreos/update.conf', 'name': 'Coreos'}, + {'path': '/etc/flatcar/update.conf', 'name': 'Flatcar'}, {'path': '/etc/os-release', 'name': 'NA'}, ) diff --git a/lib/ansible/modules/hostname.py b/lib/ansible/modules/hostname.py index 07762b7f82..1669a64357 100644 --- a/lib/ansible/modules/hostname.py +++ b/lib/ansible/modules/hostname.py @@ -677,6 +677,12 @@ class CoreosHostname(Hostname): strategy_class = SystemdStrategy +class FlatcarHostname(Hostname): + platform = 'Linux' + distribution = 'Flatcar' + strategy_class = SystemdStrategy + + class ScientificHostname(Hostname): platform = 'Linux' distribution = 'Scientific' diff --git a/test/units/module_utils/basic/test_platform_distribution.py b/test/units/module_utils/basic/test_platform_distribution.py index a59386b2d2..d7a4510c75 100644 --- a/test/units/module_utils/basic/test_platform_distribution.py +++ b/test/units/module_utils/basic/test_platform_distribution.py @@ -70,6 +70,9 @@ class TestGetDistribution: with patch('ansible.module_utils.distro.id', return_value="debian"): assert get_distribution() == "Debian" + with patch('ansible.module_utils.distro.id', return_value="flatcar"): + assert get_distribution() == "Flatcar" + with patch('ansible.module_utils.distro.id', return_value="linuxmint"): assert get_distribution() == "Linuxmint" diff --git a/test/units/module_utils/common/test_sys_info.py b/test/units/module_utils/common/test_sys_info.py index 1fd31bac96..cd68225da3 100644 --- a/test/units/module_utils/common/test_sys_info.py +++ b/test/units/module_utils/common/test_sys_info.py @@ -59,6 +59,9 @@ class TestGetDistribution: with patch('ansible.module_utils.distro.id', return_value="debian"): assert get_distribution() == "Debian" + with patch('ansible.module_utils.distro.id', return_value="flatcar"): + assert get_distribution() == "Flatcar" + with patch('ansible.module_utils.distro.id', return_value="linuxmint"): assert get_distribution() == "Linuxmint" diff --git a/test/units/module_utils/facts/system/distribution/fixtures/flatcar_2492.0.0.json b/test/units/module_utils/facts/system/distribution/fixtures/flatcar_2492.0.0.json new file mode 100644 index 0000000000..618b22598c --- /dev/null +++ b/test/units/module_utils/facts/system/distribution/fixtures/flatcar_2492.0.0.json @@ -0,0 +1,24 @@ +{ + "name": "Flatcar Container Linux", + "input": { + "/usr/lib/os-release": "NAME=\"Flatcar Container Linux by Kinvolk\"\nID=flatcar\nID_LIKE=coreos\nVERSION=2492.0.0\nVERSION_ID=2492.0.0\nBUILD_ID=2020-04-28-2210\nPRETTY_NAME=\"Flatcar Container Linux by Kinvolk 2492.0.0 (Rhyolite)\"\nANSI_COLOR=\"38;5;75\"\nHOME_URL=\"https://flatcar-linux.org/\"\nBUG_REPORT_URL=\"https://issues.flatcar-linux.org\"", + "/etc/lsb-release": "DISTRIB_ID=\"Flatcar Container Linux by Kinvolk\"\nDISTRIB_RELEASE=2492.0.0\nDISTRIB_CODENAME=\"Rhyolite\"\nDISTRIB_DESCRIPTION=\"Flatcar Container Linux by Kinvolk 2492.0.0 (Rhyolite)\"" + }, + "platform.dist": ["", "", ""], + "distro": { + "codename": "Rhyolite", + "id": "flatcar", + "id_like": "coreos", + "name": "Flatcar", + "version": "2492.0.0", + "version_best": "2492.0.0", + "os_release_info": {}, + "lsb_release_info": {} + }, + "platform.release": "", + "result": { + "distribution": "Flatcar", + "distribution_major_version": "2492", + "distribution_version": "2492.0.0" + } +} |