Skip to content
This repository has been archived by the owner on May 31, 2021. It is now read-only.

Linuxbrew #130

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Installs [Homebrew][homebrew] on MacOS, and configures packages, taps, and cask

## Requirements

None.
On MacOS, make sure the command-line tools are installed. One way to do this is by adding the role [elliotweiser.osx-command-line-tools][dep-osx-clt-role].

## Role Variables

Expand All @@ -19,12 +19,12 @@ Available variables are listed below, along with default values (see [`defaults/

The GitHub repository for Homebrew core.

homebrew_prefix: /usr/local
homebrew_prefix: "{{ (ansible_os_family == 'Darwin') | ternary('/usr/local', '/home/linuxbrew/.linuxbrew') }}"
homebrew_install_path: "{{ homebrew_prefix }}/Homebrew"

The path where Homebrew will be installed (`homebrew_prefix` is the parent directory). It is recommended you stick to the default, otherwise Homebrew might have some weird issues. If you change this variable, you should also manually create a symlink back to /usr/local so things work as Homebrew expects.

homebrew_brew_bin_path: /usr/local/bin
homebrew_brew_bin_path: "{{ homebrew_prefix }}/bin"

The path where `brew` will be installed.

Expand Down Expand Up @@ -53,7 +53,7 @@ Taps you would like to make sure Homebrew has tapped.
- firefox
- { name: virtualbox, install_options:"debug,appdir=/Applications" }

Apps you would like to have installed via `cask`. [Search][caskroom] for popular apps to see if they're available for install via Cask. Cask will not be used if it is not included in the list of taps in the `homebrew_taps` variable. You can optionally add flags to the install by setting an `install_options` property, and if used, you need to explicitly set the `name` for the package as well. By default, no Cask apps will be installed (`homebrew_cask_apps: []`).
Apps you would like to have installed via `cask`. [Search][caskroom] for popular apps to see if they're available for install via Cask. Cask will not be used if it is not included in the list of taps in the `homebrew_taps` variable. You can optionally add flags to the install by setting an `install_options` property, and if used, you need to explicitly set the `name` for the package as well. By default, no Cask apps will be installed (`homebrew_cask_apps: []`). The Cask options are only used on MacOS.

homebrew_cask_accept_external_apps: true

Expand Down Expand Up @@ -94,17 +94,14 @@ The group that you would like to use while installing Homebrew.

Any additional folders inside `homebrew_prefix` for which to ensure homebrew user/group ownership.

## Dependencies

- [elliotweiser.osx-command-line-tools][dep-osx-clt-role]

## Example Playbook

- hosts: localhost
vars:
homebrew_installed_packages:
- mysql
roles:
- elliotweiser.osx-command-line-tools
- geerlingguy.homebrew

See the `tests/local-testing` directory for an example of running this role over
Expand Down
2 changes: 1 addition & 1 deletion defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
homebrew_repo: https://github.com/Homebrew/brew

homebrew_prefix: /usr/local
homebrew_prefix: "{{ (ansible_os_family == 'Darwin') | ternary('/usr/local', '/home/linuxbrew/.linuxbrew') }}"
homebrew_install_path: "{{ homebrew_prefix }}/Homebrew"
homebrew_brew_bin_path: "{{ homebrew_prefix }}/bin"

Expand Down
8 changes: 4 additions & 4 deletions meta/main.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
---
dependencies:
- elliotweiser.osx-command-line-tools

galaxy_info:
author: geerlingguy
description: Homebrew for macOS
description: Homebrew for macOS and Debian
company: "Midwestern Mac, LLC"
license: "license (BSD, MIT)"
min_ansible_version: 2.5
platforms:
- name: Debian
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should also work on Ubuntu the way it's currently structured. And with a couple tweaks mentioned elsewhere in this review, it should also work on EL (Red Hat / CentOS) and Fedora.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess I assumed that the platforms in the meta file were the same as ansible_os_family.

See below.

versions:
- all
- name: MacOSX
versions:
- all
Expand Down
25 changes: 8 additions & 17 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,11 @@
homebrew_user: '{{ homebrew_user | default(ansible_user_id) }}'
homebrew_group: '{{ homebrew_group | default(ansible_user_gid) }}'

# Homebrew setup prerequisites.
- name: Ensure Homebrew parent directory has correct permissions (MacOS >= 10.13).
file:
path: "{{ homebrew_prefix }}"
owner: root
state: directory
become: yes
when: "ansible_distribution_version is version('10.13', '>=')"
- include_tasks: setup-Darwin.yml
when: ansible_os_family == 'Darwin'

- name: Ensure Homebrew parent directory has correct permissions (MacOS < 10.13).
file:
path: "{{ homebrew_prefix }}"
owner: root
group: admin
state: directory
mode: 0775
become: yes
when: "ansible_distribution_version is version('10.13', '<')"
- include_tasks: setup-Debian.yml
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should work on other Linux flavors too, right? For example, CentOS or Ubuntu?

Ideally, I want to get tests added for those platforms (though that requires restructuring the Travis CI tests a little so I can use base images like I do for my other roles like geerlingguy.apache for linux, versus Travis CI's macOS execution environments that I currently do, depending on the test matrix).

But doing this (naming the setup tasks Debian means that it wouldn't work for any other distros besides Debian (and I guess Ubuntu since it's keying on ansible_os_family).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See below.

when: ansible_os_family == 'Debian'

- name: Ensure Homebrew directory exists.
file:
Expand Down Expand Up @@ -107,6 +94,7 @@
- name: Ensure blacklisted cask applications are not installed.
homebrew_cask: "name={{ item }} state=absent"
loop: "{{ homebrew_cask_uninstalled_apps }}"
when: ansible_os_family == 'Darwin'

- name: Install configured cask applications.
homebrew_cask:
Expand All @@ -117,6 +105,7 @@
loop: "{{ homebrew_cask_apps }}"
notify:
- Clear homebrew cache
when: ansible_os_family == 'Darwin'

# Brew.
- name: Ensure blacklisted homebrew packages are not installed.
Expand Down Expand Up @@ -152,3 +141,5 @@
# the `homebrew_user` doesn't match the `ansible_user_id`
become: "{{ (homebrew_user != ansible_user_id) | bool }}"
become_user: "{{ homebrew_user }}"
environment:
PATH: "{{ ansible_env.PATH }}:{{ homebrew_brew_bin_path }}"
19 changes: 19 additions & 0 deletions tasks/setup-Darwin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
# Homebrew setup prerequisites.
- name: Ensure Homebrew parent directory has correct permissions (MacOS >= 10.13).
file:
path: "{{ homebrew_prefix }}"
owner: root
state: directory
become: yes
when: "ansible_distribution_version is version('10.13', '>=')"

- name: Ensure Homebrew parent directory has correct permissions (MacOS < 10.13).
file:
path: "{{ homebrew_prefix }}"
owner: root
group: admin
state: directory
mode: 0775
become: yes
when: "ansible_distribution_version is version('10.13', '<')"
30 changes: 30 additions & 0 deletions tasks/setup-Debian.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
- name: Ensure that gcc is available.
apt:
name: gcc
state: present
update_cache: yes
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I typically let playbooks set update_cache in their own pre_tasks rather than in a role itself. I would rather not add this parameter here for consistency's sake.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a better solution is to remove this step entirely. As I said at the top, this is the only step that is specific to Debian. Subject to testing/debugging.

become: yes

- name: Check if homebrew grandparent directory is already in place.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically 'parent' (not grandparent) according to the registered var name?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More context:

- name: Check if homebrew grandparent directory is already in place.
  stat:
    path: "{{ homebrew_prefix | dirname }}"
  register: homebrew_prefix_parent
  check_mode: no

In defaults/main.yml we have

homebrew_install_path: "{{ homebrew_prefix }}/Homebrew"

My thinking is that

  • homebrew_install_path is the "homebrew directory" (more precisely the "homebrew install directory")
  • homebrew_prefix is the "homebrew parent directory"
  • homebrew_prefix | dirname is the "homebrew grandparent directory"

so I do not think we want to replace "grandparent" with "parent" here. If you think this is confusing, then we can come up with something better.

Or maybe I should just change homebrew_prefix_parent to homebrew_grandparent?

stat:
path: "{{ homebrew_prefix | dirname }}"
register: homebrew_prefix_parent
check_mode: no

- name: Ensure Homebrew grandparent directory is in place.
file:
path: "{{ homebrew_prefix | dirname }}"
owner: root
group: root
state: directory
become: yes
when: not homebrew_prefix_parent.stat.exists

- name: Ensure Homebrew parent directory is in place.
file:
path: "{{ homebrew_prefix }}"
owner: "{{ homebrew_user }}"
group: "{{ homebrew_group }}"
state: directory
become: yes
4 changes: 2 additions & 2 deletions vars/main.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
---
homebrew_folders_base:
- Caskroom
- Cellar
- Homebrew
- Frameworks
- Caskroom
- Homebrew
- bin
- etc
- include
Expand Down