ansible-collection-mac icon indicating copy to clipboard operation
ansible-collection-mac copied to clipboard

Workaround to overcome the homebrew role failing because of PATH

Open juan-vg opened this issue 2 years ago • 6 comments

Intro

It's still unclear to me, but this error seems to happen on ARM-based macOS

What you could get

When using the homebrew role in a playbook as follows

roles:
  - elliotweiser.osx-command-line-tools
  - geerlingguy.mac.homebrew

you could get errors like Failed to find required executable brew in paths

TASK [homebrew : Ensure configured taps are tapped.] ***************************
failed: [default] (item=homebrew/core) => {"ansible_loop_var": "item", "changed": false, "item": "homebrew/core", "msg": "Failed to find required executable brew in paths: /opt/homebrew/Homebrew:/usr/bin:/bin:/usr/sbin:/sbin"}
failed: [default] (item=homebrew/cask) => {"ansible_loop_var": "item", "changed": false, "item": "homebrew/cask", "msg": "Failed to find required executable brew in paths: /opt/homebrew/Homebrew:/usr/bin:/bin:/usr/sbin:/sbin"}
failed: [default] (item=adoptopenjdk/openjdk) => {"ansible_loop_var": "item", "changed": false, "item": "adoptopenjdk/openjdk", "msg": "Failed to find required executable brew in paths: /opt/homebrew/Homebrew:/usr/bin:/bin:/usr/sbin:/sbin"}

How to solve it

tasks:
  - name: Install HomeBrew
    include_role:
      name: geerlingguy.mac.homebrew
      apply:
        environment:
          PATH: '{{homebrew_install_path}}/bin:{{ ansible_env.PATH }}'

juan-vg avatar Jul 13 '22 10:07 juan-vg

I came across the same error in issue #47 and i also did the same thing. After that i used an export command in the .zshrc to not longer have to deal with this in the playbooks.

JuSenshi avatar Jul 18 '22 16:07 JuSenshi

Note that what I currently do is add this to my instructions:

https://github.com/geerlingguy/mac-dev-playbook#installation

Run the following command to add Python 3 to your $PATH: export PATH="$HOME/Library/Python/3.8/bin:/opt/homebrew/bin:$PATH"

And in my dotfiles, I have this line: https://github.com/geerlingguy/dotfiles/blob/master/.zshrc#L22

geerlingguy avatar Jul 28 '22 21:07 geerlingguy

I would prefer an automation step in stead of an instruction.

dspolleke avatar Sep 01 '22 13:09 dspolleke

I agree with @dspolleke. This should be definitely automated and able to work out of the box.

Additionally, I had to add another env var (HOMEBREW_FORCE_BREWED_CURL) to make it work with M1

tasks:
  - name: Install HomeBrew
    include_role:
      name: geerlingguy.mac.homebrew
      apply:
        environment:
          PATH: '{{homebrew_install_path}}/bin:{{ ansible_env.PATH }}'
          HOMEBREW_FORCE_BREWED_CURL: 1

juan-vg avatar Sep 01 '22 15:09 juan-vg

Something like that could work — I've traditionally just updated the path by hand, but if someone were willing to make a PR I would be willing to merge.

geerlingguy avatar Sep 01 '22 16:09 geerlingguy

Would this be something we fix in the collection / role. but i do not see how i can include this in the tasks/main.yml file or where it should be implemented. We could fix it in the mac-dev-playbook. i would prefer to fix it here...

dspolleke avatar Sep 02 '22 10:09 dspolleke

This issue has been marked 'stale' due to lack of recent activity. If there is no further activity, the issue will be closed in another 30 days. Thank you for your contribution!

Please read this blog post to see the reasons why I mark issues as stale.

stale[bot] avatar Dec 21 '22 07:12 stale[bot]

This issue has been closed due to inactivity. If you feel this is in error, please reopen the issue or file a new issue with the relevant details.

stale[bot] avatar Jan 21 '23 09:01 stale[bot]