Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Install MacOS Homebrew Packages With Ansible
---
- name: Install MacOS Packages
hosts: localhost
become: false
vars:
brew_cask_packages:
- atom
- docker
- dropbox
- firefox
- google-chrome
- google-drive
- google-hangouts
- iterm2
- keepassx
- kodi
- lastpass
- macvim
- royal-tsx
- skype
- slack
- sling
- spotify
- sublime-text
- vagrant
- vagrant-manager
- virtualbox
- virtualbox-extension-pack
- visual-studio-code
- vmware-fusion
brew_packages:
- autoconf
- bash-completion
- boot2docker
- consul
- docker-compose
- docker-machine
- doxygen
- git
- git-lfs
- go
- jq
- nmap
- nomad
- openssl
- packer
- pyenv
- python
- rancher-compose
- rbenv
- ruby-build
- ssh-copy-id
- terraform
- terraform-inventory
- terraform-provisioner-ansible
- tmux
- tree
- vault
- wget
- zsh
- zsh-syntax-highlighting
install_homebrew_if_missing: false
# python_modules:
# - configparser
# - pylint
# - virtualenv
upgrade_homebrew_packages: false
pre_tasks:
- name: Ensuring Homebrew Is Installed
stat:
path: /usr/local/bin/brew
register: homebrew_check
- name: Fail If Homebrew Is Not Installed and install_homebrew_if_missing Is False
fail:
msg: Homebrew is missing...Install from http://brew.sh/
when:
- not homebrew_check.stat.exists
- not install_homebrew_if_missing
- name: Installing Homebrew
shell: /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
when:
- not homebrew_check.stat.exists
- install_homebrew_if_missing
tasks:
- name: Updating Homebrew
homebrew:
update_homebrew: true
when: homebrew_check.stat.exists
- name: Upgrading Homebrew Packages
homebrew:
upgrade_all: "{{ upgrade_homebrew_packages }}"
register: result
until: result is successful
when: homebrew_check.stat.exists
- name: Installing Homebrew Cask Packages
homebrew_cask:
name: "{{ brew_cask_packages }}"
state: present
register: result
until: result is successful
when: homebrew_check.stat.exists
- name: Installing Homebrew Packages
homebrew:
name: "{{ brew_packages }}"
state: present
register: result
until: result is successful
when: homebrew_check.stat.exists
# - name: Installing Python Modules
# pip:
# name: "{{ item }}"
# state: present
# with_items: '{{ python_modules }}'
@kgopi05
Copy link

kgopi05 commented Feb 8, 2020

Hi brew installation getting failed with below error message
"stderr": "-e:1: $(' is not allowed as a global variable name", "stderr_lines": ["-e:1: $(' is not allowed as a global variable name"], "stdout": "", "stdout_lines": []}

@mrlesmithjr
Copy link
Author

mrlesmithjr commented Feb 8, 2020

See if this works better for you now!

@kgopi05
Copy link

kgopi05 commented Feb 8, 2020

Now the different error ..
fatal: []: FAILED! => {
"changed": true,
"cmd": [
"/usr/bin/ruby",
"-e",
"$(curl",
"-fsSL",
"https://raw.githubusercontent.com/Homebrew/install/master/install)"
],
"delta": "0:00:00.015565",
"end": "2020-02-08 21:20:24.648350",
"failed": true,
"invocation": {
"module_args": {
"_raw_params": "/usr/bin/ruby -e $(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)",
"_uses_shell": false,
"chdir": null,
"creates": null,
"executable": null,
"removes": null,
"warn": true
}
},
"rc": 1,
"start": "2020-02-08 21:20:24.632785",
"stderr": "/usr/bin/ruby: invalid option -f (-h will show valid options) (RuntimeError)",
"stderr_lines": [
"/usr/bin/ruby: invalid option -f (-h will show valid options) (RuntimeError)"
],
"stdout": "",
"stdout_lines": []
}

@mrlesmithjr
Copy link
Author

mrlesmithjr commented Feb 8, 2020

Try again with the latest? If you still get the same error try to manually install HomeBrew and see if it works:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Reference

@kgopi05
Copy link

kgopi05 commented Feb 8, 2020

Thanks for your time for helping me out .. Still getting below error . When i try to install manually , it prompts me for the user password , then it downloads & install the Xcode , finally it installed the homebrew successfully.
"stderr": "-e:1: $(' is not allowed as a global variable name", "stderr_lines": [ "-e:1: $(' is not allowed as a global variable name"
],

@mrlesmithjr
Copy link
Author

mrlesmithjr commented Feb 8, 2020

That is strange indeed. And no worries.

@mrlesmithjr
Copy link
Author

mrlesmithjr commented Feb 8, 2020

You also may be interested in https://github.com/mrlesmithjr/dotfiles

@Sushmagangaiah
Copy link

Sushmagangaiah commented Jun 3, 2020

Not able to install homebrew,facing below error

TASK [Install Homebrew] ************************************************************************************************************************************************
fatal: [X.X.X.X]: FAILED! => {"changed": true, "cmd": "/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)\"", "delta": "0:00:00.429026", "end": "2020-06-03 19:18:02.430156", "msg": "non-zero return code", "rc": 1, "start": "2020-06-03 19:18:02.001130", "stderr": "", "stderr_lines": [], "stdout": "Don't run this as root!", "stdout_lines": ["Don't run this as root!"

Playbook module to install homebrew which i am trying

- name: Check if Homebrew is already installed
  stat:
    path: /usr/local/bin/brew
  register: b

- name: Install Homebrew
  shell: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
  when: not b.stat.exists

@dalisoft
Copy link

dalisoft commented Jun 4, 2020

@Sushmagangaiah Remove user and app from sudoers. Also this way will not work on servers when you already in root.
I also think about how-to install Homebrew in servers, maybe create issue on Homebrew repo?

@shariyatha
Copy link

shariyatha commented Feb 25, 2021

FAILED! => {"attempts": 3, "changed": false, "msg": "Error: Unknown command: cask"}.. installation is getting failed. pls help

@vladdoster
Copy link

vladdoster commented Oct 1, 2021

FAILED! => {"attempts": 3, "changed": false, "msg": "Error: Unknown command: cask"}.. installation is getting failed. pls help

Cask has been deprecated

@ssk512
Copy link

ssk512 commented Apr 9, 2022

fatal: [10.196.6.156]: FAILED! => {
"ansible_job_id": "72073781856.41171",
"changed": true,
"cmd": "/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)\"",
"delta": "0:00:00.206795",
"end": "2022-04-09 03:08:31.683349",
"finished": 1,
"invocation": {
"module_args": {
"_raw_params": "/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)\"",
"_uses_shell": true,
"argv": null,
"chdir": null,
"creates": null,
"executable": null,
"removes": null,
"stdin": "P@ssword123",
"stdin_add_newline": true,
"strip_empty_ends": true,
"warn": true
}
},
"msg": "non-zero return code",
"rc": 1,
"start": "2022-04-09 03:08:31.476554",
"stderr": "Don't run this as root!",
"stderr_lines": [
"Don't run this as root!"
],
"stdout": "Warning: Running in non-interactive mode because stdin is not a TTY.\n==> Checking for sudo access (which may request your password)...",
"stdout_lines": [
"Warning: Running in non-interactive mode because stdin is not a TTY.",
"==> Checking for sudo access (which may request your password)..."
]
}

PLAY RECAP ***********************************************************************************************************

I am getting above error while installing

@mrlesmithjr
Copy link
Author

mrlesmithjr commented Jul 17, 2022

@stywen This is no longer maintained here but you may find some use in the following repos:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment