ansible-role-osx-ci
ansible-role-osx-ci copied to clipboard
"Failed to find required executable brew in paths" on arm-based (M1) mac
Hi, Thanks for the work on this role. I'm setting up a new M1 mac mini (Big Sur 11.0.1) and hitting the following:
TASK [stack/modules/3rd-party-tools/ansible/roles/osx-cicd : Update Homebrew] ******************************************************************************************************
fatal: [10.1.10.21]: FAILED! => {"changed": false, "msg": "Failed to find required executable brew in paths: /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"}
Looks like homebrew's install script installs to a different directory for arm-based machines (the newer M1 processor): /opt/homebrew/bin.
TASK [stack/modules/3rd-party-tools/ansible/roles/osx-cicd : Installing homebrew] **************************************************************************************************
changed: [10.1.10.21] => {"changed": true, "rc": 0, "stderr": "Shared connection to 10.1.10.21 closed.\r\n", "stderr_lines": ["Shared connection to 10.1.10.21 closed."], "stdout": "\u001b[1;34m==>\u001b[1;39m This script will install:\u001b[0m\r\n/opt/homebrew/bin/brew\r\n/opt/homebrew/share/doc/homebrew\r\n/opt/homebrew/share/man/man1/brew.1\r\n/opt/homebrew/share/zsh/site-functions/_brew\r\n/opt/homebrew/etc/bash_completion.d/brew\r\n/opt/homebrew\r\n\u001b[1;34m==>\u001b[1;39m /usr/bin/sudo /usr/sbin/chown athos:admin /opt/homebrew\u001b[0m\r\n\u001b[1;34m==>\u001b[1;39m Downloading and installing Homebrew...\u001b[0m\r\nHEAD is now at e172f0704 Merge pull request #10360 from Rylan12/bash-completions-files\r\n\u001b[1;31mWarning\u001b[0m: /opt/homebrew/bin is not in your PATH.\r\n\u001b[1;34m==>\u001b[1;39m Installation successful!\u001b[0m\r\n\r\n\u0007\u001b[1;34m==>\u001b[1;39m Homebrew has enabled anonymous aggregate formulae and cask analytics.\u001b[0m\r\n\u001b[1;39mRead the analytics documentation (and how to opt-out) here:\r\n \u001b[4;39mhttps://docs.brew.sh/Analytics\u001b[0m\r\nNo analytics data has been sent yet (or will be during this `install` run).\r\n\r\n\u001b[1;34m==>\u001b[1;39m Homebrew is run entirely by unpaid volunteers. Please consider donating:\u001b[0m\r\n \u001b[4;39mhttps://github.com/Homebrew/brew#donations\u001b[0m\r\n\r\n\u001b[1;34m==>\u001b[1;39m Next steps:\u001b[0m\r\n- Add Homebrew to your \u001b[1;39mPATH\u001b[0m in \u001b[4;39m/Users/athos/.zprofile\u001b[0m:\r\n echo 'eval $(/opt/homebrew/bin/brew shellenv)' >> /Users/athos/.zprofile\r\n eval $(/opt/homebrew/bin/brew shellenv)\r\n- Run `brew help` to get started\r\n- Further documentation: \r\n \u001b[4;39mhttps://docs.brew.sh\u001b[0m\r\n", "stdout_lines": ["\u001b[1;34m==>\u001b[1;39m This script will install:\u001b[0m", "/opt/homebrew/bin/brew", "/opt/homebrew/share/doc/homebrew", "/opt/homebrew/share/man/man1/brew.1", "/opt/homebrew/share/zsh/site-functions/_brew", "/opt/homebrew/etc/bash_completion.d/brew", "/opt/homebrew", "\u001b[1;34m==>\u001b[1;39m /usr/bin/sudo /usr/sbin/chown athos:admin /opt/homebrew\u001b[0m", "\u001b[1;34m==>\u001b[1;39m Downloading and installing Homebrew...\u001b[0m", "HEAD is now at e172f0704 Merge pull request #10360 from Rylan12/bash-completions-files", "\u001b[1;31mWarning\u001b[0m: /opt/homebrew/bin is not in your PATH.", "\u001b[1;34m==>\u001b[1;39m Installation successful!\u001b[0m", "", "\u0007\u001b[1;34m==>\u001b[1;39m Homebrew has enabled anonymous aggregate formulae and cask analytics.\u001b[0m", "\u001b[1;39mRead the analytics documentation (and how to opt-out) here:", " \u001b[4;39mhttps://docs.brew.sh/Analytics\u001b[0m", "No analytics data has been sent yet (or will be during this `install` run).", "", "\u001b[1;34m==>\u001b[1;39m Homebrew is run entirely by unpaid volunteers. Please consider donating:\u001b[0m", " \u001b[4;39mhttps://github.com/Homebrew/brew#donations\u001b[0m", "", "\u001b[1;34m==>\u001b[1;39m Next steps:\u001b[0m", "- Add Homebrew to your \u001b[1;39mPATH\u001b[0m in \u001b[4;39m/Users/athos/.zprofile\u001b[0m:", " echo 'eval $(/opt/homebrew/bin/brew shellenv)' >> /Users/athos/.zprofile", " eval $(/opt/homebrew/bin/brew shellenv)", "- Run `brew help` to get started", "- Further documentation: ", " \u001b[4;39mhttps://docs.brew.sh\u001b[0m"]}
I added a conditional for the creates path to brew:
- name: Installing homebrew
script: >
homebrew.sh {{ ansible_become_user | default(ansible_ssh_user) }}
{{ ansible_become_pass }}
args:
creates: "{{ '/opt/homebrew/bin/brew' if ansible_architecture == 'arm64' else '/usr/local/bin/brew' }}"
Then tried setting PATH in /etc/paths:
- name: Add /opt/homebrew/bin to PATH for arm-based Macs
become: true
ansible.builtin.lineinfile:
path: /etc/paths
line: /opt/homebrew/bin
create: yes
when: ansible_architecture == "arm64"
but apparently that is not sourced by ansible as expected. To workaround, I set PATH in my playbook:
environment:
PATH: /opt/homebrew/bin:{{ ansible_env.PATH }}
probably not the best solution, but just adding here in case anyone hits this when setting up an arm-based mac.
Thanks for the research @jashby44
Great workaround @jashby44
kidna late, but: you may get warnings from brew if your path is out of order, so:
- name: Ensure Homebrew bin directory is in path (M1)
become: yes
lineinfile:
path: /etc/paths
state: present
line: "{{ homebrew_prefix }}/bin"
insertbefore: '/usr/bin'
when:
- ansible_machine == 'arm64'
that insertbefore ensures that software installed by brew takes priority.
About the original issue: /etc/paths is not sourced until a new terminal is opened, because a helper has to read the file.
May I see the whole ansible playbook? I am just staring to study ansible. I am trying to automate the installation of applications on a Mac Apple Chip Machine.