Skip to content

Commit 9422d80

Browse files
committed
Fixes #237: Use ansible_facts instead of raw ansible_ namespace.
1 parent a7e5852 commit 9422d80

File tree

7 files changed

+22
-22
lines changed

7 files changed

+22
-22
lines changed

roles/homebrew/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ Available variables are listed below, along with default values (see [`defaults/
1414

1515
The GitHub repository for Homebrew core.
1616

17-
homebrew_prefix: "{{ (ansible_machine == 'arm64') | ternary('/opt/homebrew', '/usr/local') }}"
18-
homebrew_install_path: "{{ homebrew_prefix }}{{ '/Homebrew' if ansible_machine != 'arm64' }}"
17+
homebrew_prefix: "{{ (ansible_facts.machine == 'arm64') | ternary('/opt/homebrew', '/usr/local') }}"
18+
homebrew_install_path: "{{ homebrew_prefix }}{{ '/Homebrew' if ansible_facts.machine != 'arm64' }}"
1919

2020
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.
2121

@@ -80,11 +80,11 @@ The directory where your Brewfile is located.
8080

8181
Set to `true` to remove the Hombrew cache after any new software is installed.
8282

83-
homebrew_user: "{{ ansible_user_id }}"
83+
homebrew_user: "{{ ansible_facts.user_id }}"
8484

8585
The user that you would like to install Homebrew as.
8686

87-
homebrew_group: "{{ ansible_user_gid }}"
87+
homebrew_group: "{{ ansible_facts.user_gid }}"
8888

8989
The group that you would like to use while installing Homebrew.
9090

roles/homebrew/defaults/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
---
22
homebrew_repo: https://github.com/Homebrew/brew
33

4-
homebrew_prefix: "{{ (ansible_machine == 'arm64') | ternary('/opt/homebrew', '/usr/local') }}"
5-
homebrew_install_path: "{{ homebrew_prefix }}{{ '/Homebrew' if ansible_machine != 'arm64' }}"
4+
homebrew_prefix: "{{ (ansible_facts.machine == 'arm64') | ternary('/opt/homebrew', '/usr/local') }}"
5+
homebrew_install_path: "{{ homebrew_prefix }}{{ '/Homebrew' if ansible_facts.machine != 'arm64' }}"
66
homebrew_brew_bin_path: "{{ homebrew_prefix }}/bin"
77

88
homebrew_installed_packages: []

roles/homebrew/handlers/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
path: "{{ homebrew_cache_path.stdout | trim }}"
77
state: absent
88
when: 'homebrew_clear_cache | bool'
9-
become: "{{ (homebrew_user != ansible_user_id) | bool }}"
9+
become: "{{ (homebrew_user != ansible_facts.user_id) | bool }}"
1010
become_user: "{{ homebrew_user }}"

roles/homebrew/tasks/main.yml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
---
22
- name: Determine Homebrew ownership variables
33
set_fact:
4-
homebrew_user: '{{ homebrew_user | default(ansible_user_id) }}'
5-
homebrew_group: '{{ homebrew_group | default(ansible_user_gid) }}'
4+
homebrew_user: '{{ homebrew_user | default(ansible_facts.user_id) }}'
5+
homebrew_group: '{{ homebrew_group | default(ansible_facts.user_gid) }}'
66

77
# Homebrew setup prerequisites.
88
- name: Ensure Homebrew parent directory has correct permissions (Apple Silicon).
@@ -11,18 +11,18 @@
1111
owner: "{{ homebrew_user }}"
1212
state: directory
1313
become: true
14-
when: ansible_machine == 'arm64'
14+
when: ansible_facts.machine == 'arm64'
1515

1616
- name: Ensure Homebrew parent directory has correct permissions (Intel).
17-
when: ansible_machine == 'x86_64'
17+
when: ansible_facts.machine == 'x86_64'
1818
block:
1919
- name: Ensure Homebrew parent directory has correct permissions (MacOS >= 10.13).
2020
file:
2121
path: "{{ homebrew_prefix }}"
2222
owner: root
2323
state: directory
2424
become: true
25-
when: "ansible_distribution_version is version('10.13', '>=')"
25+
when: "ansible_facts.distribution_version is version('10.13', '>=')"
2626

2727
- name: Ensure Homebrew parent directory has correct permissions (MacOS < 10.13).
2828
file:
@@ -32,7 +32,7 @@
3232
state: directory
3333
mode: "0775"
3434
become: true
35-
when: "ansible_distribution_version is version('10.13', '<')"
35+
when: "ansible_facts.distribution_version is version('10.13', '<')"
3636

3737
- name: Check if homebrew already exists.
3838
stat:
@@ -98,7 +98,7 @@
9898
- name: Add missing folder if not on Apple-chipset
9999
set_fact:
100100
homebrew_folders_base: "{{ homebrew_folders_base + ['Homebrew'] }}"
101-
when: ansible_machine != 'arm64'
101+
when: ansible_facts.machine != 'arm64'
102102

103103
- name: Ensure proper homebrew folders are in place.
104104
file:
@@ -111,12 +111,12 @@
111111

112112
- name: Collect package manager fact.
113113
setup:
114-
filter: ansible_pkg_mgr
114+
filter: ansible_facts.pkg_mgr
115115

116116
- name: Perform brew installation.
117117
# Privilege escalation is only required for inner steps when
118-
# the `homebrew_user` doesn't match the `ansible_user_id`
119-
become: "{{ (homebrew_user != ansible_user_id) | bool }}"
118+
# the `homebrew_user` doesn't match the `ansible_facts.user_id`
119+
become: "{{ (homebrew_user != ansible_facts.user_id) | bool }}"
120120
become_user: "{{ homebrew_user }}"
121121
block:
122122
- name: Force update brew after installation.

roles/mas/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ A list of apps to ensure are installed on the computer using the Mac App Store.
3838

3939
Whether to run `mas upgrade`, which will upgrade all installed Mac App Store apps.
4040

41-
mas_path: "{{ '/opt/homebrew/bin/mas' if ansible_architecture == 'arm64' else '/usr/local/bin/mas' }}"
41+
mas_path: "{{ '/opt/homebrew/bin/mas' if ansible_facts.architecture == 'arm64' else '/usr/local/bin/mas' }}"
4242

4343
When targeting a remote Mac, the PATH isn't always correct leading to the `mas` binary not being found. This variable allows you to override the path to the `mas` binary. The defaults above work for most installations, but you may need to override this if you have a custom Homebrew installation path or other custom setup.
4444

roles/mas/defaults/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ mas_installed_apps:
1010
- { id: 497799835, name: "Xcode (8.1)" }
1111
mas_upgrade_all_apps: false
1212
mas_signin_dialog: false
13-
mas_path: "{{ '/opt/homebrew/bin/mas' if ansible_architecture == 'arm64' else '/usr/local/bin/mas' }}"
13+
mas_path: "{{ '/opt/homebrew/bin/mas' if ansible_facts.architecture == 'arm64' else '/usr/local/bin/mas' }}"

roles/mas/tasks/main.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
check_mode: false
1212
changed_when: false
1313
when:
14-
- ansible_distribution_version is version('12', '<')
14+
- ansible_facts.distribution_version is version('12', '<')
1515

1616
- name: Sign in to MAS when email and password are provided.
1717
command: '"{{ mas_path }}" signin "{{ mas_email }}" "{{ mas_password }}"'
1818
register: mas_signin_result
1919
when:
20-
- ansible_distribution_version is version('10.13', '<')
20+
- ansible_facts.distribution_version is version('10.13', '<')
2121
- mas_account_result.rc == 1
2222
- mas_email is truthy
2323
- mas_password is truthy
@@ -27,7 +27,7 @@
2727
command: '"{{ mas_path }}" signin "{{ mas_email }}" "{{ mas_password }}" --dialog'
2828
register: mas_signin_result
2929
when:
30-
- ansible_distribution_version is version('10.13', '<')
30+
- ansible_facts.distribution_version is version('10.13', '<')
3131
- mas_signin_dialog
3232
- mas_account_result.rc == 1
3333
- mas_email is truthy

0 commit comments

Comments
 (0)