|
1 | 1 | --- |
2 | 2 | # tasks file for ansible-osx-command-line-tools |
3 | 3 |
|
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' |
6 | 13 | msg: Target host is not running Mac OS X |
7 | | - when: ansible_distribution != 'MacOSX' |
| 14 | + when: ansible_version is version('2.7', '<') |
8 | 15 |
|
9 | 16 | - name: Remove existing Command Line Tools installation |
10 | 17 | file: |
11 | | - path: '{{ clt_path }}' |
| 18 | + path: '{{ osx_clt_path }}' |
12 | 19 | state: absent |
13 | | - when: force_install |
| 20 | + when: osx_clt_force_install |
14 | 21 | become: yes |
15 | 22 |
|
16 | 23 | - name: Check that the Command Line Tools path is present |
17 | 24 | stat: |
18 | | - path: '{{ clt_path }}' |
19 | | - register: clt |
| 25 | + path: '{{ osx_clt_path }}' |
| 26 | + register: osx_clt_stat |
20 | 27 |
|
21 | 28 | - name: Is the C++ compiler useable? |
22 | 29 | command: g++ --version |
23 | | - register: compiler |
| 30 | + register: osx_clt_compiler |
24 | 31 | check_mode: no |
25 | 32 | ignore_errors: true |
26 | 33 | changed_when: false |
27 | 34 |
|
28 | 35 | - name: Check the Command Line Tools package metadata |
29 | 36 | command: pkgutil --pkg-info=com.apple.pkg.CLTools_Executables |
30 | | - register: pkg_info |
| 37 | + register: osx_clt_pkg_info |
31 | 38 | check_mode: no |
32 | 39 | ignore_errors: true |
33 | 40 | changed_when: false |
34 | 41 |
|
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) |
0 commit comments