-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary of Changes ------------------ * Rename role variables with `osx_clt_` prefix * DRY up install task `when` condition by moving tasks to a `block` * Detection of `ansible_distribution` is now an `assert`ion. * Add Command Line Tools tmp file path to vars * Update README with new variables as a table
- Loading branch information
1 parent
f17776a
commit 9f63276
Showing
6 changed files
with
59 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
--- | ||
# defaults file for ansible-osx-command-line-tools | ||
|
||
force_install: no | ||
osx_clt_force_install: no |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,73 @@ | ||
--- | ||
# tasks file for ansible-osx-command-line-tools | ||
|
||
- name: Am I running on Mac OS X? | ||
fail: | ||
- name: Am I running on Mac OS X? (Ansible >= 2.7) | ||
assert: | ||
that: ansible_distribution == 'MacOSX' | ||
fail_msg: Target host is not running Mac OS X | ||
when: ansible_version is version('2.7', '>=') | ||
|
||
- name: Am I running on Mac OS X? (Ansible < 2.7) | ||
assert: | ||
that: ansible_distribution == 'MacOSX' | ||
msg: Target host is not running Mac OS X | ||
when: ansible_distribution != 'MacOSX' | ||
when: ansible_version is version('2.7', '<') | ||
|
||
- name: Remove existing Command Line Tools installation | ||
file: | ||
path: '{{ clt_path }}' | ||
path: '{{ osx_clt_path }}' | ||
state: absent | ||
when: force_install | ||
when: osx_clt_force_install | ||
become: yes | ||
|
||
- name: Check that the Command Line Tools path is present | ||
stat: | ||
path: '{{ clt_path }}' | ||
register: clt | ||
path: '{{ osx_clt_path }}' | ||
register: osx_clt_stat | ||
|
||
- name: Is the C++ compiler useable? | ||
command: g++ --version | ||
register: compiler | ||
register: osx_clt_compiler | ||
check_mode: no | ||
ignore_errors: true | ||
changed_when: false | ||
|
||
- name: Check the Command Line Tools package metadata | ||
command: pkgutil --pkg-info=com.apple.pkg.CLTools_Executables | ||
register: pkg_info | ||
register: osx_clt_pkg_info | ||
check_mode: no | ||
ignore_errors: true | ||
changed_when: false | ||
|
||
- name: Prepare to install Command Line Tools | ||
file: | ||
path: /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress | ||
state: touch | ||
when: pkg_info.rc != 0 or compiler.rc != 0 or not clt.stat.exists | ||
|
||
- name: Check for Command Line Tools in Software Update list | ||
shell: > | ||
softwareupdate -l | | ||
grep -B 1 -E 'Command Line Tools' | | ||
awk -F'*' '/^ +\*/ {print $2}' | | ||
sed 's/^ *//' | | ||
grep -iE '[0-9|.]' | | ||
sort | | ||
tail -n1 | ||
register: su_list | ||
when: pkg_info.rc != 0 or compiler.rc != 0 or not clt.stat.exists | ||
changed_when: false | ||
failed_when: su_list.rc != 0 or su_list.stdout|length == 0 | ||
|
||
- name: Install Command Line Tools | ||
command: softwareupdate -i '{{ su_list.stdout }}' | ||
when: pkg_info.rc != 0 or compiler.rc != 0 or not clt.stat.exists | ||
notify: | ||
- Cleanup | ||
register: su_result | ||
failed_when: >- | ||
su_result.rc != 0 or | ||
'Error installing updates.' in su_result.stdout | ||
- block: | ||
- name: Prepare to install Command Line Tools | ||
file: | ||
path: '{{ osx_clt_tmp_file }}' | ||
state: touch | ||
|
||
- name: Check for Command Line Tools in Software Update list | ||
shell: > | ||
/usr/sbin/softwareupdate -l | | ||
grep -B 1 -E 'Command Line Tools' | | ||
awk -F'*' '/^ +\*/ {print $2}' | | ||
sed 's/^ *//' | | ||
grep -iE '[0-9|.]' | | ||
sort | | ||
tail -n1 | ||
register: osx_clt_su_list | ||
changed_when: false | ||
failed_when: osx_clt_su_list.rc != 0 or osx_clt_su_list.stdout|length == 0 | ||
|
||
- name: Install Command Line Tools | ||
command: /usr/sbin/softwareupdate -i '{{ osx_clt_su_list.stdout }}' | ||
notify: | ||
- Cleanup | ||
register: osx_clt_su_result | ||
failed_when: >- | ||
osx_clt_su_result.rc != 0 or | ||
'Error installing updates.' in osx_clt_su_result.stdout | ||
when: >- | ||
osx_clt_pkg_info.rc != 0 or | ||
osx_clt_compiler.rc != 0 or | ||
not osx_clt_stat.stat.exists or | ||
(osx_clt_force_install | bool) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
--- | ||
# vars file for ansible-osx-command-line-tools | ||
|
||
clt_path: /Library/Developer/CommandLineTools | ||
osx_clt_path: /Library/Developer/CommandLineTools | ||
osx_clt_tmp_file: /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress |