#Tried to install it on ubuntu 24.04 with anisble script but got homebrew error

1 messages · Page 1 of 1 (latest)

true ridgeBOT
#

To help others find answers, you can mark your question as solved via Right click solution message -> Apps -> ✅ Mark Solution

deft meteorBOT
#

That error is coming straight from the Homebrew installer: it refuses to run as root. In Ansible this usually happens because your play (or ansible-playbook --become) is running that task with become: true, or you’re connecting as the root user.

Fix (recommended Ansible approach)

  1. Keep deps as root, but run the brew install as a normal user.

Example:

- hosts: localhost
  become: true
  tasks:
    - name: Install Homebrew dependencies (Ubuntu)
      apt:
        update_cache: true
        name:
          - build-essential
#
          - curl
          - file
          - git
        state: present

    - name: Install Homebrew (MUST NOT be root)
      become: false           # <- important
      environment:
        NONINTERACTIVE: "1"
      shell: /bin/bash -lc '$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)'

If your whole playbook uses become: true, the become: false on that specific task is the key.

  1. Also make sure you’re not connecting as root. For example:
  • run ansible-playbook -u <youruser> ...
#
  • or set remote_user: <youruser> in the play

If this is a fresh box where you only have root, create a user first (as root), then run the brew install task as that user (become_user: youruser, with become: true on the task but switching user away from root).

Quick sanity check

On the machine, the installer must see:

whoami
# should NOT be root

If you paste the relevant part of your playbook (the play header + that task), I can point out exactly where it’s forcing root.

hidden solar
#

can i create a new account and run it on there as sudo?

deft meteorBOT
# hidden solar can i create a new account and run it on there as sudo?

Yes — that’s a common fix on Ubuntu when you only have/rooted your way into the box.

What you want is:

  • create a normal user
  • give them sudo (so Ansible can still install packages)
  • but run the Homebrew installer as that user, not as root

Manually (on the Ubuntu box)

sudo adduser brewuser
sudo usermod -aG sudo brewuser

# switch to that user (pick one)
su - brewuser
# or
#
sudo -iu brewuser

Then run the brew install without sudo as brewuser.

In Ansible (typical pattern)

  1. Create the user with become/root.
  2. Install brew as that user:
- name: Ensure brew user exists
  become: true
  user:
    name: brewuser
    groups: sudo