-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.yaml
111 lines (95 loc) · 3.36 KB
/
main.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
---
- name: Check CPU chip architecture for arm64 or x86_64
ansible.builtin.command: /usr/bin/uname -m
changed_when: false
register: cpu_arch_output
- name: Display CPU architecture
ansible.builtin.debug:
var: cpu_arch_output.stdout
- name: Set CPU architecture variable
ansible.builtin.set_fact:
cpu_arch: '{{ cpu_arch_output.stdout }}'
when: "'x86_64' in cpu_arch_output.stdout"
- name: Check if Homebrew is installed on x86_64
ansible.builtin.stat:
path: /usr/local/bin/brew
register: homebrew_check_x86_64
when: cpu_arch == 'x86_64'
- name: Check if Homebrew is installed on arm64
ansible.builtin.stat:
path: /opt/homebrew/bin/brew
register: homebrew_check_arm64
when: cpu_arch == 'arm64'
- name: Display Homebrew check for x86_64
ansible.builtin.debug:
var: homebrew_check_x86_64
when: cpu_arch == 'x86_64'
- name: Display Homebrew check for arm64
ansible.builtin.debug:
var: homebrew_check_arm64
when: cpu_arch == 'arm64'
# On ARM macOS, this script installs to /opt/homebrew only
# On Intel macOS, this script installs to /usr/local only
- name: Installing Homebrew
ansible.builtin.shell: '/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"'
when:
- "(not (homebrew_check_x86_64.stat.exists | default(false)) and cpu_arch == 'x86_64') or (not (homebrew_check_arm64.stat.exists | default(false)) and cpu_arch == 'arm64')"
register: brew_install
- name: Display Homebrew installation
when: brew_install.changed
ansible.builtin.debug:
msg: "{{ brew_install.stdout }}"
- name: Add Homebrew to PATH on arm64
ansible.builtin.shell: |
HOMEBREW_PREFIX="/opt/homebrew"
case "${SHELL}" in
*/bash*)
shell_rcfile="${HOME}/.bash_profile"
;;
*/zsh*)
shell_rcfile="${ZDOTDIR:-"${HOME}"}/.zprofile"
;;
*/fish*)
shell_rcfile="${HOME}/.config/fish/config.fish"
;;
*)
shell_rcfile="${ENV:-"${HOME}/.profile"}"
;;
esac
(echo; echo 'eval "\$(${HOMEBREW_PREFIX}/bin/brew shellenv)"') >> ${shell_rcfile}
eval "\$(${HOMEBREW_PREFIX}/bin/brew shellenv)"
when: brew_install.changed and homebrew_check_arm64.stat.exists | default(false)
- name: Add Homebrew to PATH on x86_64
ansible.builtin.shell: |
HOMEBREW_PREFIX="/usr/local"
case "${SHELL}" in
*/bash*)
shell_rcfile="${HOME}/.bash_profile"
;;
*/zsh*)
shell_rcfile="${ZDOTDIR:-"${HOME}"}/.zprofile"
;;
*/fish*)
shell_rcfile="${HOME}/.config/fish/config.fish"
;;
*)
shell_rcfile="${ENV:-"${HOME}/.profile"}"
;;
esac
(echo; echo 'eval "\$(${HOMEBREW_PREFIX}/bin/brew shellenv)"') >> ${shell_rcfile}
eval "\$(${HOMEBREW_PREFIX}/bin/brew shellenv)"
when: brew_install.changed and homebrew_check_x86_64.stat.exists | default(false)
- name: Run 'which brew' command
changed_when: false
ansible.builtin.command: which brew
register: which_brew
- name: Display where 'brew' is installed
ansible.builtin.debug:
msg: "'brew' is installed to: {{ which_brew.stdout }}"
- name: Run 'brew --version' command
changed_when: false
ansible.builtin.command: brew --version
register: brew_version
- name: Display which version of 'brew' is installed
ansible.builtin.debug:
msg: "'brew' is installed with version: {{ brew_version.stdout }}"