diff options
author | Fernando Correia <fernando@dominodatalab.com> | 2021-05-17 03:37:11 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-17 05:37:11 -0500 |
commit | 5ee1fe26657a1cd9721d524a0b9b216e6f4c8caa (patch) | |
tree | ab8830785e061a21a2114af3eb861fef49d09aaa | |
parent | 71fc9ec3936d42bb162ae8751881800575871d62 (diff) | |
download | ansible-5ee1fe26657a1cd9721d524a0b9b216e6f4c8caa.tar.gz |
Detect Homebrew on Mac M1 (Apple Silicon) (#74378) (#74401)
Homebrew's default install location for macOS on ARM is /opt/homebrew.
Source: https://docs.brew.sh/FAQ
On a Mac M1 (Apple Silicon), homebrew will be installed at
/opt/homebrew/bin/brew.
-rw-r--r-- | changelogs/fragments/73887.mac-m1-homebrew.yaml | 3 | ||||
-rw-r--r-- | lib/ansible/module_utils/facts/system/pkg_mgr.py | 1 | ||||
-rw-r--r-- | test/units/module_utils/facts/test_collectors.py | 40 |
3 files changed, 44 insertions, 0 deletions
diff --git a/changelogs/fragments/73887.mac-m1-homebrew.yaml b/changelogs/fragments/73887.mac-m1-homebrew.yaml new file mode 100644 index 0000000000..08cfd6911c --- /dev/null +++ b/changelogs/fragments/73887.mac-m1-homebrew.yaml @@ -0,0 +1,3 @@ +--- +bugfixes: + - facts - detect homebrew installed at /opt/homebrew/bin/brew diff --git a/lib/ansible/module_utils/facts/system/pkg_mgr.py b/lib/ansible/module_utils/facts/system/pkg_mgr.py index ea257fe577..664c362e40 100644 --- a/lib/ansible/module_utils/facts/system/pkg_mgr.py +++ b/lib/ansible/module_utils/facts/system/pkg_mgr.py @@ -25,6 +25,7 @@ PKG_MGRS = [{'path': '/usr/bin/yum', 'name': 'yum'}, {'path': '/opt/tools/bin/pkgin', 'name': 'pkgin'}, {'path': '/opt/local/bin/port', 'name': 'macports'}, {'path': '/usr/local/bin/brew', 'name': 'homebrew'}, + {'path': '/opt/homebrew/bin/brew', 'name': 'homebrew'}, {'path': '/sbin/apk', 'name': 'apk'}, {'path': '/usr/sbin/pkg', 'name': 'pkgng'}, {'path': '/usr/sbin/swlist', 'name': 'swdepot'}, diff --git a/test/units/module_utils/facts/test_collectors.py b/test/units/module_utils/facts/test_collectors.py index d9fe79bffa..83d5487105 100644 --- a/test/units/module_utils/facts/test_collectors.py +++ b/test/units/module_utils/facts/test_collectors.py @@ -238,6 +238,46 @@ class TestPkgMgrFacts(BaseFactsTest): self.assertIn('pkg_mgr', facts_dict) +class TestMacOSXPkgMgrFacts(BaseFactsTest): + __test__ = True + gather_subset = ['!all', 'pkg_mgr'] + valid_subsets = ['pkg_mgr'] + fact_namespace = 'ansible_pkgmgr' + collector_class = PkgMgrFactCollector + collected_facts = { + "ansible_distribution": "MacOSX", + "ansible_distribution_major_version": "11", + "ansible_os_family": "Darwin" + } + + @patch('ansible.module_utils.facts.system.pkg_mgr.os.path.exists', side_effect=lambda x: x == '/opt/homebrew/bin/brew') + def test_collect_opt_homebrew(self, p_exists): + module = self._mock_module() + fact_collector = self.collector_class() + facts_dict = fact_collector.collect(module=module, collected_facts=self.collected_facts) + self.assertIsInstance(facts_dict, dict) + self.assertIn('pkg_mgr', facts_dict) + self.assertEqual(facts_dict['pkg_mgr'], 'homebrew') + + @patch('ansible.module_utils.facts.system.pkg_mgr.os.path.exists', side_effect=lambda x: x == '/usr/local/bin/brew') + def test_collect_usr_homebrew(self, p_exists): + module = self._mock_module() + fact_collector = self.collector_class() + facts_dict = fact_collector.collect(module=module, collected_facts=self.collected_facts) + self.assertIsInstance(facts_dict, dict) + self.assertIn('pkg_mgr', facts_dict) + self.assertEqual(facts_dict['pkg_mgr'], 'homebrew') + + @patch('ansible.module_utils.facts.system.pkg_mgr.os.path.exists', side_effect=lambda x: x == '/opt/local/bin/port') + def test_collect_macports(self, p_exists): + module = self._mock_module() + fact_collector = self.collector_class() + facts_dict = fact_collector.collect(module=module, collected_facts=self.collected_facts) + self.assertIsInstance(facts_dict, dict) + self.assertIn('pkg_mgr', facts_dict) + self.assertEqual(facts_dict['pkg_mgr'], 'macports') + + def _sanitize_os_path_apt_get(path): if path == '/usr/bin/apt-get': return True |