From a5d0d191721ea7635f64b842343010eb93bb8062 Mon Sep 17 00:00:00 2001 From: Benji Fisher Date: Sat, 29 Feb 2020 16:30:22 -0500 Subject: [PATCH 01/16] Sort the directories in homebrew_folders_base --- vars/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vars/main.yml b/vars/main.yml index 109fe6d..e14c1c0 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -1,9 +1,9 @@ --- homebrew_folders_base: + - Caskroom - Cellar - - Homebrew - Frameworks - - Caskroom + - Homebrew - bin - etc - include From 6013e32f3d7a946d5c5d2eacfdf4ed0e3836397a Mon Sep 17 00:00:00 2001 From: Benji Fisher Date: Sat, 29 Feb 2020 16:25:36 -0500 Subject: [PATCH 02/16] Move Mac-version-specific tasks to an included task --- tasks/main.yml | 20 ++------------------ tasks/setup-Darwin.yml | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 18 deletions(-) create mode 100644 tasks/setup-Darwin.yml diff --git a/tasks/main.yml b/tasks/main.yml index 07c79e6..1a116ff 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -4,24 +4,8 @@ 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', '>=')" - -- 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-Darwin.yml + when: ansible_os_family == 'Darwin' - name: Ensure Homebrew directory exists. file: diff --git a/tasks/setup-Darwin.yml b/tasks/setup-Darwin.yml new file mode 100644 index 0000000..93b471c --- /dev/null +++ b/tasks/setup-Darwin.yml @@ -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', '<')" From 25a6d03714f0b577e444553721687dff74f73eb3 Mon Sep 17 00:00:00 2001 From: Benji Fisher Date: Sat, 29 Feb 2020 16:26:35 -0500 Subject: [PATCH 03/16] Only do Cask tasks on Mac --- tasks/main.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tasks/main.yml b/tasks/main.yml index 1a116ff..d07969c 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -91,6 +91,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: @@ -101,6 +102,7 @@ loop: "{{ homebrew_cask_apps }}" notify: - Clear homebrew cache + when: ansible_os_family == 'Darwin' # Brew. - name: Ensure blacklisted homebrew packages are not installed. From 22275015103d89f1c28d9a1a25a162a46afca5cf Mon Sep 17 00:00:00 2001 From: Benji Fisher Date: Sat, 29 Feb 2020 16:27:39 -0500 Subject: [PATCH 04/16] Remove dependency on osx-command-line-tools --- meta/main.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/meta/main.yml b/meta/main.yml index f1a0def..6f702e1 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -1,7 +1,4 @@ --- -dependencies: - - elliotweiser.osx-command-line-tools - galaxy_info: author: geerlingguy description: Homebrew for macOS From f09949bcad31c66c8187604a9bd6665790c099bd Mon Sep 17 00:00:00 2001 From: Benji Fisher Date: Sat, 29 Feb 2020 16:29:47 -0500 Subject: [PATCH 05/16] Set homebrew_prefix depending on ansible_os_family --- defaults/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/defaults/main.yml b/defaults/main.yml index dfa752f..9d48a90 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -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" From bee0e2187e8952c476edb7854c0ccb17e4fe930a Mon Sep 17 00:00:00 2001 From: Benji Fisher Date: Sat, 29 Feb 2020 17:17:34 -0500 Subject: [PATCH 06/16] Add setup tasks for Linux --- tasks/main.yml | 3 +++ tasks/setup-Debian.yml | 30 ++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 tasks/setup-Debian.yml diff --git a/tasks/main.yml b/tasks/main.yml index d07969c..6fbb6c5 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -7,6 +7,9 @@ - include_tasks: setup-Darwin.yml when: ansible_os_family == 'Darwin' +- include_tasks: setup-Debian.yml + when: ansible_os_family == 'Debian' + - name: Ensure Homebrew directory exists. file: path: "{{ homebrew_install_path }}" diff --git a/tasks/setup-Debian.yml b/tasks/setup-Debian.yml new file mode 100644 index 0000000..d883dce --- /dev/null +++ b/tasks/setup-Debian.yml @@ -0,0 +1,30 @@ +--- +- name: Ensure that gcc is available. + apt: + name: gcc + state: present + update_cache: yes + become: yes + +- name: Check if homebrew grandparent directory is already in place. + 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 From 986652cea96d3e21a510a11d970b21524893e4da Mon Sep 17 00:00:00 2001 From: Benji Fisher Date: Sat, 29 Feb 2020 20:46:01 -0500 Subject: [PATCH 07/16] Add homebrew_brew_bin_path to PATH for brew* modules --- tasks/main.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tasks/main.yml b/tasks/main.yml index 6fbb6c5..4081a20 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -141,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 }}" From 36f220a931257fda6f83e35cc4c4add24c37b1b9 Mon Sep 17 00:00:00 2001 From: Benji Fisher Date: Sun, 1 Mar 2020 08:08:05 -0500 Subject: [PATCH 08/16] Add Debian to supported platforms --- meta/main.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/meta/main.yml b/meta/main.yml index 6f702e1..fb63b8e 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -1,11 +1,14 @@ --- 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 + versions: + - all - name: MacOSX versions: - all From 23d037c3b8a226f203b71f8142982f2acaf3e459 Mon Sep 17 00:00:00 2001 From: Benji Fisher Date: Sun, 1 Mar 2020 08:09:35 -0500 Subject: [PATCH 09/16] Update README to require command-line tools on MacOS --- README.md | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index d58a0c5..c8c4b43 100644 --- a/README.md +++ b/README.md @@ -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 @@ -94,10 +94,6 @@ 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 @@ -105,6 +101,7 @@ Any additional folders inside `homebrew_prefix` for which to ensure homebrew use 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 From a50ee4e973f25c7b987b6a686ce0438006a86f5f Mon Sep 17 00:00:00 2001 From: Benji Fisher Date: Sun, 1 Mar 2020 08:10:42 -0500 Subject: [PATCH 10/16] Update documentation of default variables --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c8c4b43..270500a 100644 --- a/README.md +++ b/README.md @@ -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. From f52fd5220d7da14d67609dc65e84eb379ccabf4c Mon Sep 17 00:00:00 2001 From: Benji Fisher Date: Sun, 1 Mar 2020 08:11:12 -0500 Subject: [PATCH 11/16] Document that Cask-related variables work only on MacOS --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 270500a..a0c1684 100644 --- a/README.md +++ b/README.md @@ -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 From acd2c4ca0939cffbe043c0fb25d7f5fdef70883a Mon Sep 17 00:00:00 2001 From: Benji Fisher Date: Thu, 9 Apr 2020 18:52:55 -0400 Subject: [PATCH 12/16] Do not update apt cache in a role This should normally be done in pre_tasks. --- tasks/setup-Debian.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/tasks/setup-Debian.yml b/tasks/setup-Debian.yml index d883dce..17c8a09 100644 --- a/tasks/setup-Debian.yml +++ b/tasks/setup-Debian.yml @@ -3,7 +3,6 @@ apt: name: gcc state: present - update_cache: yes become: yes - name: Check if homebrew grandparent directory is already in place. From 6bbe61784885239e94890e47d60fb69ee333f6ab Mon Sep 17 00:00:00 2001 From: Benji Fisher Date: Thu, 9 Apr 2020 19:31:46 -0400 Subject: [PATCH 13/16] Do not install gcc as part of the role Instead, do it under pre_tasks in the sample playbook. Removing this step makes the playbook work on more Linux distributions. --- tasks/playbook.yml | 9 +++++++++ tasks/setup-Debian.yml | 6 ------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/tasks/playbook.yml b/tasks/playbook.yml index e2f9c5a..b723dfb 100644 --- a/tasks/playbook.yml +++ b/tasks/playbook.yml @@ -2,5 +2,14 @@ - hosts: localhost connection: local + pre_tasks: + - name: Ensure that gcc is available. + apt: + name: gcc + state: present + update_cache: yes + become: yes + when: ansible_os_family == 'Debian' + roles: - geerlingguy.homebrew diff --git a/tasks/setup-Debian.yml b/tasks/setup-Debian.yml index 17c8a09..3b2c699 100644 --- a/tasks/setup-Debian.yml +++ b/tasks/setup-Debian.yml @@ -1,10 +1,4 @@ --- -- name: Ensure that gcc is available. - apt: - name: gcc - state: present - become: yes - - name: Check if homebrew grandparent directory is already in place. stat: path: "{{ homebrew_prefix | dirname }}" From 33cfad366a81e34d31f15f458cb2dda4036333fb Mon Sep 17 00:00:00 2001 From: Benji Fisher Date: Thu, 9 Apr 2020 19:38:45 -0400 Subject: [PATCH 14/16] Document that gcc has to be installed --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index a0c1684..bb7539f 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,8 @@ Installs [Homebrew][homebrew] on MacOS, and configures packages, taps, and cask 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]. +On Linux, make sure that `gcc` is installed. The example `tasks/playbook.yml` shows one way to do this that will work on Debian-like systems (including Ubuntu). + ## Role Variables Available variables are listed below, along with default values (see [`defaults/main.yml`](defaults/main.yml)): From 760601bc4c92abc5665307d2f0d201e1cd0cdfb6 Mon Sep 17 00:00:00 2001 From: Benji Fisher Date: Thu, 9 Apr 2020 19:44:04 -0400 Subject: [PATCH 15/16] Install on any Linux distribution --- meta/main.yml | 4 ++-- tasks/main.yml | 4 ++-- tasks/{setup-Debian.yml => setup-Linux.yml} | 0 3 files changed, 4 insertions(+), 4 deletions(-) rename tasks/{setup-Debian.yml => setup-Linux.yml} (100%) diff --git a/meta/main.yml b/meta/main.yml index fb63b8e..a3161c0 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -1,12 +1,12 @@ --- galaxy_info: author: geerlingguy - description: Homebrew for macOS and Debian + description: Homebrew for macOS and Linux company: "Midwestern Mac, LLC" license: "license (BSD, MIT)" min_ansible_version: 2.5 platforms: - - name: Debian + - name: GenericLinux versions: - all - name: MacOSX diff --git a/tasks/main.yml b/tasks/main.yml index 4081a20..d4c2dfd 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -7,8 +7,8 @@ - include_tasks: setup-Darwin.yml when: ansible_os_family == 'Darwin' -- include_tasks: setup-Debian.yml - when: ansible_os_family == 'Debian' +- include_tasks: setup-Linux.yml + when: ansible_os_family != 'Darwin' - name: Ensure Homebrew directory exists. file: diff --git a/tasks/setup-Debian.yml b/tasks/setup-Linux.yml similarity index 100% rename from tasks/setup-Debian.yml rename to tasks/setup-Linux.yml From c4fb92ddd179aa1458459e2416898882c17b1513 Mon Sep 17 00:00:00 2001 From: Benji Fisher Date: Thu, 9 Apr 2020 20:48:06 -0400 Subject: [PATCH 16/16] Add a link to Homebrew-Linux installation docs --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index bb7539f..04cbc21 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ Installs [Homebrew][homebrew] on MacOS, and configures packages, taps, and cask 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]. -On Linux, make sure that `gcc` is installed. The example `tasks/playbook.yml` shows one way to do this that will work on Debian-like systems (including Ubuntu). +On Linux, make sure that `gcc` is installed. The example `tasks/playbook.yml` shows one way to do this that will work on Debian-like systems (including Ubuntu). For further requirements, see the [Homebrew Documentation][homebrew-linux]. ## Role Variables @@ -132,6 +132,7 @@ This role was created in 2014 by [Jeff Geerling][author-website], author of [badge-travis]: https://travis-ci.org/geerlingguy/ansible-role-homebrew.svg?branch=master [caskroom]: https://caskroom.github.io/search [homebrew]: http://brew.sh/ +[homebrew-linux]: https://docs.brew.sh/Homebrew-on-Linux#linuxwsl-requirements [dep-osx-clt-role]: https://galaxy.ansible.com/elliotweiser/osx-command-line-tools/ [link-galaxy]: https://galaxy.ansible.com/geerlingguy/homebrew/ [link-license]: https://raw.githubusercontent.com/geerlingguy/ansible-role-homebrew/master/LICENSE