mirror of
https://github.com/cirruslabs/macos-image-templates.git
synced 2026-09-30 03:42:04 +02:00
* Ignore errors for "install available update" Ansible task * Do not fail when update_result is not defined
44 lines
2.0 KiB
YAML
44 lines
2.0 KiB
YAML
- name: check for available updates
|
|
command:
|
|
cmd: "softwareupdate --all --list"
|
|
register: software_updates_result
|
|
|
|
- name: parse available updates
|
|
set_fact:
|
|
software_updates: "{{ software_updates_result.stdout | regex_findall('\\* Label: (.*)\\n\\tTitle: (.*), Version: (.*), Size: (.*), Recommended: (.*), Action: (.*), .*') | map('zip', ['label', 'title', 'version', 'size', 'recommended', 'action']) | map('map', 'reverse') | map('community.general.dict') }}"
|
|
|
|
- name: print available updates
|
|
debug:
|
|
var: software_updates
|
|
|
|
# It seems that we must always pass "--restart" command-line argument to "softwareupdate",
|
|
# otherwise on the OS update the "softwareupdate" will be stuck at "Downloaded: macOS [...]"
|
|
- name: install available update
|
|
command:
|
|
cmd: "softwareupdate --install --agree-to-license --force --restart --user admin --stdinpass {{ stdinpass | default('') }} '{{ item.label }}'"
|
|
stdin: "{{ ansible_password }}"
|
|
register: update_result
|
|
# Work around the following:
|
|
# > Data could not be sent to remote host [...].
|
|
# > Make sure this host can be reached over ssh:
|
|
# > ssh: connect to host [...] port 22: Connection refused.
|
|
ignore_unreachable: yes
|
|
# Ignore SIGTERM/SIGKILL sent "softwareupdate" process
|
|
# when the system reboots due to --restart and any other errors,
|
|
# since we'll check whether the update was installed in main.yml
|
|
# anyway.
|
|
ignore_errors: yes
|
|
become: yes
|
|
loop: "{{ software_updates }}"
|
|
when: "not item.label.startswith('macOS') or item.version.split('.')[0] == ansible_facts['distribution_version'].split('.')[0]"
|
|
|
|
# Wait for the connection since the previous command could restart the host
|
|
- name: wait for connection
|
|
wait_for_connection:
|
|
# We need to wait long enough for the "softwareupdate" to initiate the reboot,
|
|
# otherwise it's possible that we'll interrupt the process by running
|
|
# the commands below on a non-restarted system.
|
|
delay: 60
|
|
timeout: 1800
|
|
when: update_result is defined and not update_result.skipped | default(false)
|