Skip to content

Commit 1e40a35

Browse files
authored
Merge pull request #115 from jaket91-1/master
Set mas_path variable to fix mas not found issue when using remote Mac as target
2 parents 34404f3 + 20a7b55 commit 1e40a35

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

roles/mas/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ 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' }}"
42+
43+
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.
44+
4145
### Remove installed apps
4246

4347
mas_uninstalled_apps:

roles/mas/defaults/main.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
mas_email: ""
33
mas_password: ""
44
mas_uninstalled_apps: []
5-
mas_installed_app_ids: [] # Deprecated
5+
mas_installed_app_ids: [] # Deprecated
66
mas_installed_apps:
7-
- {id: 425264550, name: "Blackmagic Disk Speed Test (3.0)"}
8-
- {id: 411643860, name: "DaisyDisk (4.3.2)"}
9-
- {id: 498486288, name: "Quick Resizer (1.9)"}
10-
- {id: 497799835, name: "Xcode (8.1)"}
7+
- { id: 425264550, name: "Blackmagic Disk Speed Test (3.0)" }
8+
- { id: 411643860, name: "DaisyDisk (4.3.2)" }
9+
- { id: 498486288, name: "Quick Resizer (1.9)" }
10+
- { 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' }}"

roles/mas/tasks/main.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
state: present
66

77
- name: Get MAS account status
8-
command: mas account
8+
command: '"{{ mas_path }}" account'
99
register: mas_account_result
1010
failed_when: mas_account_result.rc > 1
1111
check_mode: false
@@ -14,7 +14,7 @@
1414
- ansible_distribution_version is version('12', '<')
1515

1616
- name: Sign in to MAS when email and password are provided.
17-
command: 'mas signin "{{ mas_email }}" "{{ mas_password }}"'
17+
command: '"{{ mas_path }}" signin "{{ mas_email }}" "{{ mas_password }}"'
1818
register: mas_signin_result
1919
when:
2020
- ansible_distribution_version is version('10.13', '<')
@@ -24,7 +24,7 @@
2424
- not mas_signin_dialog
2525

2626
- name: Sign in to MAS when email is provided, and complete password and 2FA using dialog.
27-
command: 'mas signin "{{ mas_email }}" "{{ mas_password }}" --dialog'
27+
command: '"{{ mas_path }}" signin "{{ mas_email }}" "{{ mas_password }}" --dialog'
2828
register: mas_signin_result
2929
when:
3030
- ansible_distribution_version is version('10.13', '<')
@@ -33,21 +33,21 @@
3333
- mas_email is truthy
3434

3535
- name: List installed MAS apps.
36-
command: mas list
36+
command: '"{{ mas_path }}" list'
3737
register: mas_list
3838
check_mode: false
3939
changed_when: false
4040

4141
- name: Ensure unwanted MAS apps are uninstalled.
42-
command: mas uninstall "{{ item.id | default(item) }}"
42+
command: '"{{ mas_path }}" uninstall "{{ item.id | default(item) }}"'
4343
with_items: "{{ mas_uninstalled_apps }}"
4444
when: (item.id | default(item) | string) in mas_list.stdout
4545

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

5151
- name: Upgrade all apps (if configured).
52-
command: mas upgrade
52+
command: '"{{ mas_path }}" upgrade'
5353
when: mas_upgrade_all_apps

0 commit comments

Comments
 (0)