Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding tags to the homebrew tasks main.yml #101

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from
53 changes: 53 additions & 0 deletions roles/homebrew/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
state: directory
become: true
when: ansible_machine == 'arm64'
tags:
- permissions
- permission_check_homebrew_directory

- name: Ensure Homebrew parent directory has correct permissions (Intel).
when: ansible_machine == 'x86_64'
Expand All @@ -23,6 +26,9 @@
state: directory
become: true
when: "ansible_distribution_version is version('10.13', '>=')"
tags:
- permissions
- permission_check_homebrew_directory

- name: Ensure Homebrew parent directory has correct permissions (MacOS < 10.13).
file:
Expand All @@ -33,6 +39,9 @@
mode: 0775
become: true
when: "ansible_distribution_version is version('10.13', '<')"
tags:
- permissions
- permission_check_homebrew_directory

- name: Ensure Homebrew directory exists.
file:
Expand All @@ -42,6 +51,15 @@
state: directory
mode: 0775
become: true
tags:
- directories
- check_homebrew_directory_exists

- name: Register contents of homebrew_install_path
ansible.builtin.command: ls -A
args:
chdir: "{{ homebrew_install_path }}"
register: homebrew_dir

# Clone Homebrew.
- name: Ensure Homebrew is installed.
Expand All @@ -53,6 +71,9 @@
depth: 1
become: true
become_user: "{{ homebrew_user }}"
tags:
- check_homebrew_installed
when: homebrew_dir["stdout_lines"] | length == 0

# Adjust Homebrew permissions.
- name: Ensure proper permissions and ownership on homebrew_brew_bin_path dirs.
Expand All @@ -63,6 +84,9 @@
group: "{{ homebrew_group }}"
mode: 0775
become: true
tags:
- permissions
- permission_check_bin_directory

- name: Ensure proper ownership on homebrew_install_path subdirs.
file:
Expand All @@ -72,13 +96,18 @@
group: "{{ homebrew_group }}"
recurse: true
become: true
tags:
- permissions
- permission_check_install_directory

# Place brew binary in proper location and complete setup.
- name: Check if homebrew binary is already in place.
stat:
path: "{{ homebrew_brew_bin_path }}/brew"
register: homebrew_binary
check_mode: false
tags:
- check_homebrew_binary_exists

- name: Symlink brew to homebrew_brew_bin_path.
file:
Expand All @@ -87,6 +116,9 @@
state: link
when: not homebrew_binary.stat.exists
become: true
tags:
- symlinks
- symlink_homebrew_binary

- name: Add missing folder if not on Apple-chipset
set_fact:
Expand All @@ -101,6 +133,9 @@
group: "{{ homebrew_group }}"
become: true
loop: "{{ homebrew_folders_base + homebrew_folders_additional }}"
tags:
- directories
- check_homebrew_directories_exist

- name: Collect package manager fact.
setup:
Expand All @@ -115,6 +150,8 @@
- name: Force update brew after installation.
command: "{{ homebrew_brew_bin_path }}/brew update --force"
when: not homebrew_binary.stat.exists
tags:
- force_brew_update

- name: Where is the cache?
command: "{{ homebrew_brew_bin_path }}/brew --cache"
Expand All @@ -129,6 +166,8 @@
url: '{{ item.url | default(omit) }}'
state: present
loop: "{{ homebrew_taps }}"
tags:
- taps

# Cask.
- name: Ensure blacklisted cask applications are not installed.
Expand All @@ -137,6 +176,8 @@
state: absent
sudo_password: "{{ ansible_become_password | default(omit) }}"
loop: "{{ homebrew_cask_uninstalled_apps }}"
tags:
- block_blacklisted_casks

- name: Install configured cask applications.
homebrew_cask:
Expand All @@ -148,13 +189,17 @@
loop: "{{ homebrew_cask_apps }}"
notify:
- Clear homebrew cache
tags:
- install_casks

# Brew.
- name: Ensure blacklisted homebrew packages are not installed.
homebrew:
name: "{{ item }}"
state: absent
loop: "{{ homebrew_uninstalled_packages }}"
tags:
- block_blacklisted_packages

- name: Ensure configured homebrew packages are installed.
homebrew:
Expand All @@ -165,6 +210,8 @@
loop: "{{ homebrew_installed_packages }}"
notify:
- Clear homebrew cache
tags:
- install_packages

- name: Upgrade all homebrew packages (if configured).
homebrew:
Expand All @@ -173,13 +220,19 @@
when: homebrew_upgrade_all_packages
notify:
- Clear homebrew cache
tags:
- upgrade_packages

- name: Check for Brewfile.
stat:
path: "{{ homebrew_brewfile_dir }}/Brewfile"
register: homebrew_brewfile
check_mode: false
tags:
- check_for_brewfile

- name: Install from Brewfile.
command: "{{ homebrew_brew_bin_path }}/brew bundle chdir={{ homebrew_brewfile_dir }}"
when: homebrew_brewfile.stat.exists and homebrew_use_brewfile
tags:
- install_from_brewfile
15 changes: 12 additions & 3 deletions tests/uninstall-homebrew.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,16 @@ curl -sLO https://raw.githubusercontent.com/Homebrew/install/master/uninstall.sh
chmod +x ./uninstall.sh
sudo ./uninstall.sh --force


# Clean up Homebrew directories.
sudo rm -rf /usr/local/Homebrew
sudo rm -rf /usr/local/Caskroom
sudo rm -rf /usr/local/bin/brew
system_arch=$(uname -p)
case $system_arch in
arm)
sudo rm -rf /opt/homebrew
;;
*)
sudo rm -rf /usr/local/Homebrew
sudo rm -rf /usr/local/Caskroom
sudo rm -rf /usr/local/bin/brew
;;
esac
Loading