Repository navigation
reInstall_macos
github-actions[bot] edited this page Dec 14, 2024
·
2 revisions
This set of Ansible modules provides automation for controlling macOS updates and installation on remote hosts. They enable you to:
-
Disable Automatic Updates (using
softwareupdate_auto_settings):- A helper module (not extensively documented here) that simply enables or disables all automatic updates in macOS. In our use case, we disable them to ensure manual control via Ansible, preventing macOS from self-updating automatically.
-
Download the Full macOS Installer (
softwareupdate_download_osapp):- Uses the
softwareupdate --fetch-full-installercommand to download a specific full macOS installer of a desired version. - After completion, an installer application directory should appear under
/Applications(e.g.,Install macOS Sonoma.app).
- Uses the
-
Start macOS Installation (
softwareupdate_osinstall):- Initiates the macOS installation process using the
startosinstalltool from the previously downloaded installer. - Runs the installation in the background, allowing the machine to reboot automatically to complete the installation process.
- Initiates the macOS installation process using the
By default, macOS manages updates automatically. However, you may need controlled, predictable updates in an environment with numerous macOS hosts. These modules let you:
- Prevent automatic, unsolicited updates from macOS itself.
- Precisely control which macOS version to download and when.
- Integrate macOS updating and upgrading into your existing Ansible workflows, CI/CD pipelines, or IT orchestration tools.
- Ansible and SSH access to the target macOS machines.
-
become: true(root privileges) to run the tasks. - Supported macOS major versions: 13 (Ventura), 14 (Sonoma), and 15 (Sequoia). This is due to differences in the
softwareupdatebehavior and installation commands. - Ensure
softwareupdateandstartosinstallare available on the target macOS machine.
The following playbook demonstrates:
- Disabling all automatic updates (
softwareupdate_auto_settings). - Listing available macOS installer versions (using
softwareupdate_list_installers—assumed to be available). - Downloading a specific full installer (
softwareupdate_download_osapp). - Starting the macOS installation process (
softwareupdate_osinstall).
macmachines:
hosts:
macos-vm1:
ansible_host: 192.168.0.61
ansible_user: admin
vars:
ansible_python_interpreter: /opt/homebrew/bin/python3
---
- hosts: macmachines
gather_facts: false
become: true
tasks:
# 1. Disable all automatic updates
- name: Disable all automatic updates
softwareupdate_auto_settings:
automatic_check_enabled: false
automatic_download: false
automatically_install_macos_updates: false
config_data_install: false
critical_update_install: false
app_auto_update: false
# 2. List available macOS installers
- name: List macOS installers
softwareupdate_list_installers:
latest_only: true
version_pattern: '^14\.'
register: installers_result
- debug:
var: installers_result.installers
# 3. Download a specific macOS installer (e.g., 14.x version)
- name: Download a specific macOS installer by version
softwareupdate_download_osapp:
macos_version: "{{ installers_result.installers[0].version }}"
register: download_result
- debug:
var: download_result
# 4. Start the macOS installation from the full installer
- name: Install macOS from full installer
softwareupdate_osinstall:
version: 14
username: "admin"
password: "admin"- Disable all automatic updates: Ensures that macOS won't update itself, leaving Ansible in full control.
- List macOS installers: Gets a list of available macOS installers that can be fetched.
- Download a specific macOS installer: Fetches the chosen full installer (e.g., Sonoma 14.7.2). Once complete, you should see /Applications/Install macOS Sonoma.app.
- Install macOS from full installer: Initiates the OS upgrade process. The machine will reboot and proceed with the installation.