Skip to content

Commit dc8935c

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 fffcb65 commit dc8935c

File tree

6 files changed

+52
-43
lines changed

6 files changed

+52
-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: 41 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,65 +2,68 @@
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
35+
- block:
36+
- name: Prepare to install Command Line Tools
37+
file:
38+
path: '{{ osx_clt_tmp_file }}'
39+
state: touch
4040

41-
- name: Check for Command Line Tools in Software Update list
42-
shell: >
43-
set -o pipefail;
44-
softwareupdate -l |
45-
grep -B 1 -E 'Command Line Tools' |
46-
awk -F'*' '/^ +\*/ {print $2}' |
47-
sed 's/^ *//' |
48-
grep -iE '[0-9|.]' |
49-
sort |
50-
tail -n1
51-
args:
52-
executable: /bin/bash
53-
register: su_list
54-
when: pkg_info.rc != 0 or compiler.rc != 0 or not clt.stat.exists
55-
changed_when: false
56-
failed_when: su_list.rc != 0 or su_list.stdout|length == 0
41+
- name: Check for Command Line Tools in Software Update list
42+
shell: >
43+
set -o pipefail;
44+
/usr/sbin/softwareupdate -l |
45+
grep -B 1 -E 'Command Line Tools' |
46+
awk -F'*' '/^ +\*/ {print $2}' |
47+
sed 's/^ *//' |
48+
grep -iE '[0-9|.]' |
49+
sort |
50+
tail -n1
51+
args:
52+
executable: /bin/bash
53+
register: osx_clt_su_list
54+
changed_when: false
55+
failed_when: osx_clt_su_list.rc != 0 or osx_clt_su_list.stdout|length == 0
5756

58-
- name: Install Command Line Tools
59-
command: softwareupdate -i '{{ su_list.stdout }}'
60-
when: pkg_info.rc != 0 or compiler.rc != 0 or not clt.stat.exists
61-
notify:
62-
- Cleanup
63-
register: su_result
64-
failed_when: >-
65-
su_result.rc != 0 or
66-
'Error installing updates.' in su_result.stdout
57+
- name: Install Command Line Tools
58+
command: /usr/sbin/softwareupdate -i '{{ osx_clt_su_list.stdout }}'
59+
notify:
60+
- Cleanup
61+
register: osx_clt_su_result
62+
failed_when: >-
63+
osx_clt_su_result.rc != 0 or
64+
'Error installing updates.' in osx_clt_su_result.stdout
65+
when: >-
66+
osx_clt_pkg_info.rc != 0 or
67+
osx_clt_compiler.rc != 0 or
68+
not osx_clt_stat.stat.exists or
69+
(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)