summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRick Elrod <rick@elrod.me>2021-02-02 21:09:30 +0100
committerGitHub <noreply@github.com>2021-02-02 21:09:30 +0100
commit9a9272305a7b09f84861c7061f57945ae9ad7090 (patch)
tree928202e043e340c8928edca9f9e8f95e20d32a3c
parentAllow `$` & `~` inside paths in galaxy roles (#72966) (diff)
downloadansible-9a9272305a7b09f84861c7061f57945ae9ad7090.tar.xz
ansible-9a9272305a7b09f84861c7061f57945ae9ad7090.zip
Correct pkg_mgr for Fedora-derived OSTree distros (#73445)
Change: - Remove check that states that only Fedora can be an OSTree distribution. - This allows us to correctly return "atomic_container" as the pkg_mgr fact for RHEL for Edge, Fedora/RHEL/CentOS Atomic Host, etc. Test Plan: - Created local RHEL for Edge image and tested against it. - Tested against regular RHEL 8 and still got `dnf` as expected. - Tested against RHEL 7 Atomic Host and got `atomic_container` now. - New unit tests. Tickets: - Fixes #73084 Signed-off-by: Rick Elrod <rick@elrod.me>
-rw-r--r--changelogs/fragments/73084-rhel-for-edge-pkg_mgr-fact-fix.yml2
-rw-r--r--lib/ansible/module_utils/facts/system/pkg_mgr.py5
-rw-r--r--test/units/module_utils/facts/test_ansible_collector.py20
3 files changed, 25 insertions, 2 deletions
diff --git a/changelogs/fragments/73084-rhel-for-edge-pkg_mgr-fact-fix.yml b/changelogs/fragments/73084-rhel-for-edge-pkg_mgr-fact-fix.yml
new file mode 100644
index 0000000000..f890144c9f
--- /dev/null
+++ b/changelogs/fragments/73084-rhel-for-edge-pkg_mgr-fact-fix.yml
@@ -0,0 +1,2 @@
+bugfixes:
+ - ansible_pkg_mgr fact - now correctly returns ``atomic_container`` when run on "RHEL for Edge" images and Fedora/RHEL/CentOS Atomic Host (https://github.com/ansible/ansible/issues/73084).
diff --git a/lib/ansible/module_utils/facts/system/pkg_mgr.py b/lib/ansible/module_utils/facts/system/pkg_mgr.py
index be9f029f55..ea257fe577 100644
--- a/lib/ansible/module_utils/facts/system/pkg_mgr.py
+++ b/lib/ansible/module_utils/facts/system/pkg_mgr.py
@@ -61,9 +61,10 @@ class PkgMgrFactCollector(BaseFactCollector):
required_facts = set(['distribution'])
def _check_rh_versions(self, pkg_mgr_name, collected_facts):
+ if os.path.exists('/run/ostree-booted'):
+ return "atomic_container"
+
if collected_facts['ansible_distribution'] == 'Fedora':
- if os.path.exists('/run/ostree-booted'):
- return "atomic_container"
try:
if int(collected_facts['ansible_distribution_major_version']) < 23:
for yum in [pkg_mgr for pkg_mgr in PKG_MGRS if pkg_mgr['name'] == 'yum']:
diff --git a/test/units/module_utils/facts/test_ansible_collector.py b/test/units/module_utils/facts/test_ansible_collector.py
index 6c23648666..47d88df99e 100644
--- a/test/units/module_utils/facts/test_ansible_collector.py
+++ b/test/units/module_utils/facts/test_ansible_collector.py
@@ -482,6 +482,26 @@ class TestPkgMgrFacts(TestCollectedFacts):
}
+class TestPkgMgrOSTreeFacts(TestPkgMgrFacts):
+ @patch(
+ 'ansible.module_utils.facts.system.pkg_mgr.os.path.exists',
+ side_effect=lambda x: x == '/run/ostree-booted')
+ def _recollect_facts(self, distribution, version, mock_exists):
+ self.collected_facts['ansible_distribution'] = distribution
+ self.collected_facts['ansible_distribution_major_version'] = \
+ str(version)
+ # Recollect facts
+ self.setUp()
+ self.assertIn('pkg_mgr', self.facts)
+ self.assertEqual(self.facts['pkg_mgr'], 'atomic_container')
+
+ def test_is_rhel_edge_ostree(self):
+ self._recollect_facts('RedHat', 8)
+
+ def test_is_fedora_ostree(self):
+ self._recollect_facts('Fedora', 33)
+
+
class TestOpenBSDPkgMgrFacts(TestPkgMgrFacts):
def test_is_openbsd_pkg(self):
self.assertIn('pkg_mgr', self.facts)