Skip to content

Commit 9f63276

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 9f63276

File tree

6 files changed

+59
-43
lines changed

6 files changed

+59
-43
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: 48 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,73 @@
11
---
22
# tasks file for ansible-osx-command-line-tools
33

4-
- name: Am I running on Mac OS X?
5-
fail:
4+
- name: Am I running on Mac OS X? (Ansible >= 2.7)
5+
assert:
6+
that: ansible_distribution == 'MacOSX'
7+
fail_msg: Target host is not running Mac OS X
8+
when: ansible_version is version('2.7', '>=')
9+
10+
- name: Am I running on Mac OS X? (Ansible < 2.7)
11+
assert:
12+
that: ansible_distribution == 'MacOSX'
613
msg: Target host is not running Mac OS X
7-
when: ansible_distribution != 'MacOSX'
14+
when: ansible_version is version('2.7', '<')
815

916
- name: Remove existing Command Line Tools installation
1017
file:
11-
path: '{{ clt_path }}'
18+
path: '{{ osx_clt_path }}'
1219
state: absent
13-
when: force_install
20+
when: osx_clt_force_install
1421
become: yes
1522

1623
- name: Check that the Command Line Tools path is present
1724
stat:
18-
path: '{{ clt_path }}'
19-
register: clt
25+
path: '{{ osx_clt_path }}'
26+
register: osx_clt_stat
2027

2128
- name: Is the C++ compiler useable?
2229
command: g++ --version
23-
register: compiler
30+
register: osx_clt_compiler
2431
check_mode: no
2532
ignore_errors: true
2633
changed_when: false
2734

2835
- name: Check the Command Line Tools package metadata
2936
command: pkgutil --pkg-info=com.apple.pkg.CLTools_Executables
30-
register: pkg_info
37+
register: osx_clt_pkg_info
3138
check_mode: no
3239
ignore_errors: true
3340
changed_when: false
3441

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
42+
- block:
43+
- name: Prepare to install Command Line Tools
44+
file:
45+
path: '{{ osx_clt_tmp_file }}'
46+
state: touch
47+
48+
- name: Check for Command Line Tools in Software Update list
49+
shell: >
50+
/usr/sbin/softwareupdate -l |
51+
grep -B 1 -E 'Command Line Tools' |
52+
awk -F'*' '/^ +\*/ {print $2}' |
53+
sed 's/^ *//' |
54+
grep -iE '[0-9|.]' |
55+
sort |
56+
tail -n1
57+
register: osx_clt_su_list
58+
changed_when: false
59+
failed_when: osx_clt_su_list.rc != 0 or osx_clt_su_list.stdout|length == 0
60+
61+
- name: Install Command Line Tools
62+
command: /usr/sbin/softwareupdate -i '{{ osx_clt_su_list.stdout }}'
63+
notify:
64+
- Cleanup
65+
register: osx_clt_su_result
66+
failed_when: >-
67+
osx_clt_su_result.rc != 0 or
68+
'Error installing updates.' in osx_clt_su_result.stdout
69+
when: >-
70+
osx_clt_pkg_info.rc != 0 or
71+
osx_clt_compiler.rc != 0 or
72+
not osx_clt_stat.stat.exists or
73+
(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)