Skip to content

Commit

Permalink
WIP: Preparing for 3.0 release
Browse files Browse the repository at this point in the history
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
elliotweiser committed Nov 27, 2018
1 parent f17776a commit 2907a15
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .yamllint
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ rules:
key-duplicates: enable
key-ordering: disable
line-length:
max: 80
max: 120
allow-non-breakable-words: true
allow-non-breakable-inline-mappings: false
new-line-at-end-of-file: enable
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ None (except running on Mac OS X).
Role Variables
--------------

`force_install`: Install the Command Line Tools, even if they are already installed (Default: `no`).
Going forward, all role variables will be prefixed with `osx_clt_` (for OSX **C**ommand
**L**ine **T**ools) to avoid ambiguity and potential namespace collision.

| Variable Name | Description | Default |
| :--- | :--- | :---: |
| `osx_clt_force_install` | Install the Command Line Tools, even if already installed | `no` |

Dependencies
------------
Expand Down
2 changes: 1 addition & 1 deletion defaults/main.yml
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
2 changes: 1 addition & 1 deletion handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@

- name: Cleanup
file:
path: /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress
path: '{{ osx_clt_tmp_file }}'
state: absent
77 changes: 40 additions & 37 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,62 +2,65 @@
# tasks file for ansible-osx-command-line-tools

- name: Am I running on Mac OS X?
fail:
assert:
that: ansible_distribution == 'MacOSX'
msg: Target host is not running Mac OS X
when: ansible_distribution != 'MacOSX'

- 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)
3 changes: 2 additions & 1 deletion vars/main.yml
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

0 comments on commit 2907a15

Please sign in to comment.