Skip to content

Commit 2907a15

Browse files
committed
WIP: Preparing for 3.0 release
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
1 parent f17776a commit 2907a15

File tree

6 files changed

+51
-42
lines changed

6 files changed

+51
-42
lines changed

.yamllint

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ rules:
4141
key-duplicates: enable
4242
key-ordering: disable
4343
line-length:
44-
max: 80
44+
max: 120
4545
allow-non-breakable-words: true
4646
allow-non-breakable-inline-mappings: false
4747
new-line-at-end-of-file: enable

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ None (except running on Mac OS X).
1717
Role Variables
1818
--------------
1919

20-
`force_install`: Install the Command Line Tools, even if they are already installed (Default: `no`).
20+
Going forward, all role variables will be prefixed with `osx_clt_` (for OSX **C**ommand
21+
**L**ine **T**ools) to avoid ambiguity and potential namespace collision.
22+
23+
| Variable Name | Description | Default |
24+
| :--- | :--- | :---: |
25+
| `osx_clt_force_install` | Install the Command Line Tools, even if already installed | `no` |
2126

2227
Dependencies
2328
------------

defaults/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
---
22
# defaults file for ansible-osx-command-line-tools
33

4-
force_install: no
4+
osx_clt_force_install: no

handlers/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33

44
- name: Cleanup
55
file:
6-
path: /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress
6+
path: '{{ osx_clt_tmp_file }}'
77
state: absent

tasks/main.yml

Lines changed: 40 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,62 +2,65 @@
22
# tasks file for ansible-osx-command-line-tools
33

44
- name: Am I running on Mac OS X?
5-
fail:
5+
assert:
6+
that: ansible_distribution == 'MacOSX'
67
msg: Target host is not running Mac OS X
7-
when: ansible_distribution != 'MacOSX'
88

99
- name: Remove existing Command Line Tools installation
1010
file:
11-
path: '{{ clt_path }}'
11+
path: '{{ osx_clt_path }}'
1212
state: absent
13-
when: force_install
13+
when: osx_clt_force_install
1414
become: yes
1515

1616
- name: Check that the Command Line Tools path is present
1717
stat:
18-
path: '{{ clt_path }}'
19-
register: clt
18+
path: '{{ osx_clt_path }}'
19+
register: osx_clt_stat
2020

2121
- name: Is the C++ compiler useable?
2222
command: g++ --version
23-
register: compiler
23+
register: osx_clt_compiler
2424
check_mode: no
2525
ignore_errors: true
2626
changed_when: false
2727

2828
- name: Check the Command Line Tools package metadata
2929
command: pkgutil --pkg-info=com.apple.pkg.CLTools_Executables
30-
register: pkg_info
30+
register: osx_clt_pkg_info
3131
check_mode: no
3232
ignore_errors: true
3333
changed_when: false
3434

35-
- name: Prepare to install Command Line Tools
36-
file:
37-
path: /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress
38-
state: touch
39-
when: pkg_info.rc != 0 or compiler.rc != 0 or not clt.stat.exists
40-
41-
- name: Check for Command Line Tools in Software Update list
42-
shell: >
43-
softwareupdate -l |
44-
grep -B 1 -E 'Command Line Tools' |
45-
awk -F'*' '/^ +\*/ {print $2}' |
46-
sed 's/^ *//' |
47-
grep -iE '[0-9|.]' |
48-
sort |
49-
tail -n1
50-
register: su_list
51-
when: pkg_info.rc != 0 or compiler.rc != 0 or not clt.stat.exists
52-
changed_when: false
53-
failed_when: su_list.rc != 0 or su_list.stdout|length == 0
54-
55-
- name: Install Command Line Tools
56-
command: softwareupdate -i '{{ su_list.stdout }}'
57-
when: pkg_info.rc != 0 or compiler.rc != 0 or not clt.stat.exists
58-
notify:
59-
- Cleanup
60-
register: su_result
61-
failed_when: >-
62-
su_result.rc != 0 or
63-
'Error installing updates.' in su_result.stdout
35+
- block:
36+
- name: Prepare to install Command Line Tools
37+
file:
38+
path: '{{ osx_clt_tmp_file }}'
39+
state: touch
40+
41+
- name: Check for Command Line Tools in Software Update list
42+
shell: >
43+
/usr/sbin/softwareupdate -l |
44+
grep -B 1 -E 'Command Line Tools' |
45+
awk -F'*' '/^ +\*/ {print $2}' |
46+
sed 's/^ *//' |
47+
grep -iE '[0-9|.]' |
48+
sort |
49+
tail -n1
50+
register: osx_clt_su_list
51+
changed_when: false
52+
failed_when: osx_clt_su_list.rc != 0 or osx_clt_su_list.stdout|length == 0
53+
54+
- name: Install Command Line Tools
55+
command: /usr/sbin/softwareupdate -i '{{ osx_clt_su_list.stdout }}'
56+
notify:
57+
- Cleanup
58+
register: osx_clt_su_result
59+
failed_when: >-
60+
osx_clt_su_result.rc != 0 or
61+
'Error installing updates.' in osx_clt_su_result.stdout
62+
when: >-
63+
osx_clt_pkg_info.rc != 0 or
64+
osx_clt_compiler.rc != 0 or
65+
not osx_clt_stat.stat.exists or
66+
(osx_clt_force_install | bool)

vars/main.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
---
22
# vars file for ansible-osx-command-line-tools
33

4-
clt_path: /Library/Developer/CommandLineTools
4+
osx_clt_path: /Library/Developer/CommandLineTools
5+
osx_clt_tmp_file: /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress

0 commit comments

Comments
 (0)