diff --git a/README.md b/README.md index d58a0c5..04cbc21 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,9 @@ 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]. + +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 @@ -19,12 +21,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. @@ -53,7 +55,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 @@ -94,10 +96,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 +103,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 @@ -133,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 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" diff --git a/meta/main.yml b/meta/main.yml index f1a0def..a3161c0 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -1,14 +1,14 @@ --- -dependencies: - - elliotweiser.osx-command-line-tools - galaxy_info: author: geerlingguy - description: Homebrew for macOS + description: Homebrew for macOS and Linux company: "Midwestern Mac, LLC" license: "license (BSD, MIT)" min_ansible_version: 2.5 platforms: + - name: GenericLinux + versions: + - all - name: MacOSX versions: - all diff --git a/tasks/main.yml b/tasks/main.yml index 07c79e6..d4c2dfd 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -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-Linux.yml + when: ansible_os_family != 'Darwin' - name: Ensure Homebrew directory exists. file: @@ -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: @@ -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. @@ -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 }}" 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-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', '<')" diff --git a/tasks/setup-Linux.yml b/tasks/setup-Linux.yml new file mode 100644 index 0000000..3b2c699 --- /dev/null +++ b/tasks/setup-Linux.yml @@ -0,0 +1,23 @@ +--- +- 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 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