I am trying to configure Ansible to install all the packages defined in my Brewfile, but I am getting the following error
fatal: [localhost]: FAILED! => {"changed": true, "cmd": "brew bundle", "delta": "0:00:00.163639", "end": "2024-04-02 21:03:51.639762", "msg": "non-zero return code", "rc": 1, "start": "2024-04-02 21:03:51.476123", "stderr": "Error: Running Homebrew as root is extremely dangerous and no longer supported.\nAs Homebrew does not drop privileges on installation you would be giving all\nbuild scripts full access to your system.", "stderr_lines": ["Error: Running Homebrew as root is extremely dangerous and no longer supported.", "As Homebrew does not drop privileges on installation you would be giving all", "build scripts full access to your system."], "stdout": "", "stdout_lines": []}
This is what my files looks like
# bootstrap.yaml
- name: Bootstrap development environment
hosts: localhost
tasks:
- name: Install packages from Brewfile
become: yes
ansible.builtin.shell: brew bundle
when: ansible_distribution == "MacOSX"
# Brewfile
brew "autoconf"
brew "docker", link: false
When I run
ansible-playbook --ask-become-pass bootstrap.yml
I get the above mentioned error.
What is the reason for this error?
By the way, I have installed the community.general
collection from Ansible, and I already have Homebrew installed. AFAIK, brew bundle
is still not available in Ansible, but I do not understand why the shell command is not available.
Thanks for the comments. I have changed the file to
# bootstrap.yaml
- name: Bootstrap development environment
hosts: localhost
tasks:
- name: Install packages from Brewfile
ansible.builtin.shell: brew bundle
when: ansible_distribution == "MacOSX"
and I am now running with
ansible-playbook bootstrap.yml
without issues.