Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a platform check to homebrew role #112

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

florianpiesche
Copy link

@florianpiesche florianpiesche commented Aug 20, 2024

This will allow the use of this as a role dependency - Ansible executes role dependencies unconditionally, so it's not possible to add geerlingguy.mac.homebrew to the dependencies section in a role's meta.yml if said role might run on non-macOS hosts (as Ansible will then try to install Homebrew on a non-macOS system, which unsurprisingly fails).

With this change, the role itself will still execute when used as a dependency, but only runs its tasks if the host is indeed running macOS.

The other alternative would be to add the ansible_os_family check to every task in the role; however by having a single include_tasks main step with the check will return much more quickly on non-Mac hosts.

@geerlingguy
Copy link
Owner

Can you explain more about the use case where you'd use this role as a dependency... but not on Macs?

@florianpiesche
Copy link
Author

florianpiesche commented Sep 16, 2024

I've got a Vagrant+Ansible setup for provisioning testing VMs with a range of operating systems/versions, including RedHat, several Windows versions and multiple macOS versions. Among other things, this runs a role for setting up the desktop environment for these test machines including auto-login, with separate yaml files for each platform to do so. At the moment, this includes this block in the macOS setup branch of the role to make sure Homebrew is available on the Mac VMs:

include_role: geerlingguy.mac.homebrew
when: ansible_os == "Darwin"

There are multiple other roles in the setup workflow that depend on Homebrew-installed packages on macOS and so have the same inclusion - so it'd be quite nice if rather than manually including the role every time (as some of these roles are also reused in other workflows), I could use Ansible's dependency management to de-duplicate this from being run multiple times when provisioning Macs. However, Ansible's dependency management cannot be conditional, so the role would also be included when setting up a Rocky or Windows VM, where it unsurprisingly fails.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants