diff --git a/.yamllint b/.yamllint index c5e6158..0dee2cb 100644 --- a/.yamllint +++ b/.yamllint @@ -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 diff --git a/README.md b/README.md index a9ad3ee..d81822a 100644 --- a/README.md +++ b/README.md @@ -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 ------------ diff --git a/defaults/main.yml b/defaults/main.yml index 60e114d..eac17ef 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,4 +1,4 @@ --- # defaults file for ansible-osx-command-line-tools -force_install: no +osx_clt_force_install: no diff --git a/handlers/main.yml b/handlers/main.yml index d8ba1b9..4e57b8a 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -3,5 +3,5 @@ - name: Cleanup file: - path: /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress + path: '{{ osx_clt_tmp_file }}' state: absent diff --git a/tasks/main.yml b/tasks/main.yml index 221d92d..289b3c3 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -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) diff --git a/vars/main.yml b/vars/main.yml index 04b5eae..e2ea2d1 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -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