Skip to content

Commit

Permalink
Merge branch 'geerlingguy:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
tuxpeople authored Aug 5, 2024
2 parents 46c85e7 + 7f5765b commit b657e90
Show file tree
Hide file tree
Showing 18 changed files with 84 additions and 49 deletions.
4 changes: 4 additions & 0 deletions .ansible-lint
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@ skip_list:
- risky-file-permissions
- yaml
- fqcn-builtins
- fqcn[action]
- name[template]
- var-naming[no-role-prefix]
- no-changed-when
- galaxy[no-changelog]
9 changes: 6 additions & 3 deletions galaxy-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
# ansible-playbook -i 'localhost,' galaxy-deploy.yml \
# -e "github_tag=${{ github.ref }}"

- hosts: localhost
- name: Deploy new Collection version to Galaxy.
hosts: localhost
connection: local
gather_facts: false

Expand All @@ -24,7 +25,7 @@
- name: Ensure ANSIBLE_GALAXY_TOKEN is set.
fail:
msg: A valid ANSIBLE_GALAXY_TOKEN must be set.
when: "lookup('env','ANSIBLE_GALAXY_TOKEN') | length == 0"
when: "lookup('env', 'ANSIBLE_GALAXY_TOKEN') | length == 0"

- name: Ensure the ~/.ansible directory exists.
file:
Expand All @@ -34,7 +35,7 @@
- name: Write the Galaxy token to ~/.ansible/galaxy_token
copy:
content: |
token: {{ lookup('env','ANSIBLE_GALAXY_TOKEN') }}
token: {{ lookup('env', 'ANSIBLE_GALAXY_TOKEN') }}
dest: ~/.ansible/galaxy_token

tasks:
Expand All @@ -46,7 +47,9 @@

- name: Build the collection.
command: ansible-galaxy collection build
changed_when: true

- name: Publish the collection.
command: >
ansible-galaxy collection publish ./{{ namespace }}-{{ collection }}-{{ release_tag }}.tar.gz
changed_when: true
1 change: 1 addition & 0 deletions galaxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ license:
tags:
- mac
- macos
- tools
- osx
- homebrew
- brew
Expand Down
2 changes: 1 addition & 1 deletion meta/runtime.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---

Check failure on line 1 in meta/runtime.yml

View workflow job for this annotation

GitHub Actions / Lint

meta-runtime[unsupported-version]

'requires_ansible' key must refer to a currently supported version such as: >=2.15.0, >=2.16.0, >=2.17.0

Check failure on line 1 in meta/runtime.yml

View workflow job for this annotation

GitHub Actions / Lint

meta-runtime[unsupported-version]

'requires_ansible' key must refer to a currently supported version such as: >=2.15.0, >=2.16.0, >=2.17.0
requires_ansible: ">=2.10"
requires_ansible: ">=2.14.0"
6 changes: 0 additions & 6 deletions roles/dock/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@ dockitems_persist: []
Dock items to add. `pos` parameter is optional and will place the Dock item in a particular position in the Dock.

```yaml
dockutil_homebrew_cask: hpedrorodrigues/tools/dockutil
```

Which Homebrew cask to install for dockutil. See [this issue](https://github.com/kcrawford/dockutil/issues/127) to read more about why this cask is the default.

```yaml
dockutil_install: true
```
Expand Down
3 changes: 0 additions & 3 deletions roles/dock/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,5 @@ dockitems_persist: []
# path: "/Applications/Sublime Text.app/"
# pos: 5

# Which homebrew cask to install for dockutil
dockutil_homebrew_cask: hpedrorodrigues/tools/dockutil

# Whether to install dockutil or not
dockutil_install: true
12 changes: 8 additions & 4 deletions roles/dock/tasks/dock-add.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,18 @@
tags: ['dock']

- name: Ensure Dock item {{ item.name | default(item) }} exists.
ansible.builtin.command: "dockutil --add '{{ item.path }}' --label '{{ item.name }}'"
when: dockitem_exists.rc >0 or
ansible.builtin.command: |
dockutil --add '{{ item.path }}' --label '{{ item.name }}'
{% if not ansible_loop.last %}--no-restart{% endif %}
when: dockitem_exists.rc > 0 or
dockitem_exists.rc == 0 and current_section == 'recent-apps'
tags: ['dock']

- name: Pause for 7 seconds between dock changes.
ansible.builtin.pause:
seconds: 7
when: dockitem_exists.rc >0 or
dockitem_exists.rc == 0 and current_section == 'recent-apps'
when:
- dockitem_exists.rc > 0 or
dockitem_exists.rc == 0 and current_section == 'recent-apps'
- ansible_loop.last
tags: ['dock']
4 changes: 3 additions & 1 deletion roles/dock/tasks/dock-position.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@

- name: Move dock item to the correct position.
ansible.builtin.command:
cmd: dockutil --move '{{ item.name | default(item) }}' --position '{{ item.pos }}'
cmd: |
dockutil --move '{{ item.name | default(item) }}' --position '{{ item.pos }}'
{% if not ansible_loop.last %}--no-restart{% endif %}
when: current_position|int != item.pos|int
8 changes: 6 additions & 2 deletions roles/dock/tasks/dock-remove.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@

- name: Ensure Dock item {{ item }} is removed.
ansible.builtin.command:
cmd: dockutil --remove '{{ item }}'
cmd: |
dockutil --remove '{{ item }}'
{% if not ansible_loop.last %}--no-restart{% endif %}
when: dockitem_exists.rc == 0
tags: ['dock']

- name: Pause for 7 seconds between dock changes.
ansible.builtin.pause:
seconds: 7
when: dockitem_exists.rc == 0
when:
- dockitem_exists.rc == 0
- ansible_loop.last
tags: ['dock']
14 changes: 11 additions & 3 deletions roles/dock/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
---
# See: https://github.com/kcrawford/dockutil/issues/127
- name: Install dockutil.
community.general.homebrew_cask:
name: "{{ dockutil_homebrew_cask }}"
community.general.homebrew:
name: dockutil
state: present
notify:
- Clear homebrew cache
Expand All @@ -12,11 +11,17 @@
- name: Remove configured Dock items.
ansible.builtin.include_tasks: dock-remove.yml
loop: "{{ dockitems_remove }}"
loop_control:
extended: true
extended_allitems: false
tags: ['dock']

- name: Ensure required dock items exist.
ansible.builtin.include_tasks: dock-add.yml
loop: "{{ dockitems_persist }}"
loop_control:
extended: true
extended_allitems: false
tags: ['dock']

- name: Ensure dock items are in correct position.
Expand All @@ -25,4 +30,7 @@
- item.pos is defined
- item.pos > 0
loop: "{{ dockitems_persist }}"
loop_control:
extended: true
extended_allitems: false
tags: ['dock']
9 changes: 4 additions & 5 deletions roles/homebrew/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ Available variables are listed below, along with default values (see [`defaults/
The GitHub repository for Homebrew core.

homebrew_prefix: "{{ (ansible_machine == 'arm64') | ternary('/opt/homebrew', '/usr/local') }}"
homebrew_install_path: "{{ homebrew_prefix }}/Homebrew"
homebrew_install_path: "{{ homebrew_prefix }}{{ '/Homebrew' if ansible_machine != 'arm64' }}"

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.
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 `/opt/homebrew` (or `/usr/local` if you're on an Intel-mac) 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 All @@ -44,7 +44,6 @@ Whether to upgrade homebrew and all packages installed by homebrew. If you prefe
Whether to upgrade homebrew and all cask applications installed by homebrew. If you prefer to manually update packages via `brew` commands, leave this set to `false`.

homebrew_taps:
- homebrew/core
- { name: my_company/internal_tap, url: 'https://example.com/path/to/tap.git' }

Taps you would like to make sure Homebrew has tapped.
Expand Down Expand Up @@ -109,7 +108,7 @@ Any additional folders inside `homebrew_prefix` for which to ensure homebrew use
homebrew_installed_packages:
- mysql
roles:
- geerlingguy.homebrew
- geerlingguy.mac.homebrew

See the `tests/local-testing` directory for an example of running this role over
Ansible's `local` connection. See also:
Expand Down
5 changes: 2 additions & 3 deletions roles/homebrew/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
homebrew_repo: https://github.com/Homebrew/brew

homebrew_prefix: "{{ (ansible_machine == 'arm64') | ternary('/opt/homebrew', '/usr/local') }}"
homebrew_install_path: "{{ homebrew_prefix }}/Homebrew"
homebrew_install_path: "{{ homebrew_prefix }}{{ '/Homebrew' if ansible_machine != 'arm64' }}"
homebrew_brew_bin_path: "{{ homebrew_prefix }}/bin"

homebrew_installed_packages: []
Expand All @@ -12,8 +12,7 @@ homebrew_uninstalled_packages: []
homebrew_upgrade_all_packages: false
homebrew_cask_upgrade_all_packages: false

homebrew_taps:
- homebrew/core
homebrew_taps: []

homebrew_cask_apps: []

Expand Down
40 changes: 29 additions & 11 deletions roles/homebrew/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
when: ansible_machine == 'arm64'

- name: Ensure Homebrew parent directory has correct permissions (Intel).
when: ansible_machine == 'x86_64'
block:
- name: Ensure Homebrew parent directory has correct permissions (MacOS >= 10.13).
file:
Expand All @@ -32,7 +33,11 @@
mode: 0775
become: true
when: "ansible_distribution_version is version('10.13', '<')"
when: ansible_machine == 'x86_64'

- name: Check if homebrew already exists.
stat:
path: "{{ homebrew_brew_bin_path }}/brew"
register: pre_installed_brew

- name: Ensure Homebrew directory exists.
file:
Expand Down Expand Up @@ -75,7 +80,8 @@

# 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"
stat:
path: "{{ homebrew_brew_bin_path }}/brew"
register: homebrew_binary
check_mode: false

Expand All @@ -87,6 +93,11 @@
when: not homebrew_binary.stat.exists
become: true

- name: Add missing folder if not on Apple-chipset
set_fact:
homebrew_folders_base: "{{ homebrew_folders_base + ['Homebrew'] }}"
when: ansible_machine != 'arm64'

- name: Ensure proper homebrew folders are in place.
file:
path: "{{ homebrew_prefix }}/{{ item }}"
Expand All @@ -101,10 +112,14 @@
filter: ansible_pkg_mgr

- name: Perform brew installation.
# Privilege escalation is only required for inner steps when
# the `homebrew_user` doesn't match the `ansible_user_id`
become: "{{ (homebrew_user != ansible_user_id) | bool }}"
become_user: "{{ homebrew_user }}"
block:
- name: Force update brew after installation.
command: "{{ homebrew_brew_bin_path }}/brew update --force"
when: not homebrew_binary.stat.exists
when: not pre_installed_brew.stat.exists

- name: Where is the cache?
command: "{{ homebrew_brew_bin_path }}/brew --cache"
Expand All @@ -122,7 +137,10 @@

# Cask.
- name: Ensure blacklisted cask applications are not installed.
homebrew_cask: "name={{ item }} state=absent"
homebrew_cask:
name: "{{ item }}"
state: absent
sudo_password: "{{ ansible_become_password | default(omit) }}"
loop: "{{ homebrew_cask_uninstalled_apps }}"

- name: Install configured cask applications.
Expand Down Expand Up @@ -150,11 +168,14 @@

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

- name: Ensure configured homebrew packages are installed.
homebrew:
path: "{{ homebrew_brew_bin_path }}"
name: "{{ item.name | default(item) }}"
install_options: "{{ item.install_options | default(omit) }}"
state: "{{ item.state | default('present') }}"
Expand All @@ -163,7 +184,9 @@
- Clear homebrew cache

- name: Upgrade all homebrew packages (if configured).
homebrew: update_homebrew=yes upgrade_all=yes
homebrew:
update_homebrew: true
upgrade_all: true
when: homebrew_upgrade_all_packages
notify:
- Clear homebrew cache
Expand All @@ -177,8 +200,3 @@
- name: Install from Brewfile.

Check failure on line 200 in roles/homebrew/tasks/main.yml

View workflow job for this annotation

GitHub Actions / Lint

no-free-form

Avoid using free-form when calling module actions. (command)

Check failure on line 200 in roles/homebrew/tasks/main.yml

View workflow job for this annotation

GitHub Actions / Lint

no-free-form

Avoid using free-form when calling module actions. (command)
command: "{{ homebrew_brew_bin_path }}/brew bundle chdir={{ homebrew_brewfile_dir }}"
when: homebrew_brewfile.stat.exists and homebrew_use_brewfile

# Privilege escalation is only required for inner steps when
# the `homebrew_user` doesn't match the `ansible_user_id`
become: "{{ (homebrew_user != ansible_user_id) | bool }}"
become_user: "{{ homebrew_user }}"
1 change: 0 additions & 1 deletion roles/homebrew/vars/main.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
homebrew_folders_base:
- Cellar
- Homebrew
- Frameworks
- Caskroom
- bin
Expand Down
8 changes: 5 additions & 3 deletions roles/mas/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
---
- name: Ensure MAS is installed.
homebrew: name=mas state=present
homebrew:
name: mas
state: present

- name: Get MAS account status
command: mas account
Expand Down Expand Up @@ -37,12 +39,12 @@
changed_when: false

- name: Ensure unwanted MAS apps are uninstalled.
command: mas uninstall "{{ item.id|default(item) }}"
command: mas uninstall "{{ item.id | default(item) }}"
with_items: "{{ mas_uninstalled_apps }}"
when: (item.id | default(item) | string) in mas_list.stdout

- name: Ensure configured MAS apps are installed.
command: mas install "{{ item.id|default(item) }}"
command: mas install "{{ item.id | default(item) }}"
with_items: "{{ mas_installed_apps + mas_installed_app_ids }}"
when: (item.id | default(item) | string) not in mas_list.stdout

Expand Down
2 changes: 1 addition & 1 deletion tests/ansible.cfg
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[defaults]
inventory = inventory
collections_paths = ../../../
collections_path = ../../../
4 changes: 2 additions & 2 deletions tests/test.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
- hosts: localhost
- name: Test the collection.
hosts: localhost

vars:
homebrew_clear_cache: true
Expand All @@ -13,7 +14,6 @@
- google-chrome # from hombrew/cask

homebrew_taps:
- homebrew/core
- name: denji/nginx
url: 'https://github.com/denji/homebrew-nginx.git'

Expand Down
1 change: 1 addition & 0 deletions tests/uninstall-homebrew.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ sudo ./uninstall.sh --force
sudo rm -rf /usr/local/Homebrew
sudo rm -rf /usr/local/Caskroom
sudo rm -rf /usr/local/bin/brew
sudo rm -rf /opt/homebrew

0 comments on commit b657e90

Please sign in to comment.