Jun 20, 2023 3 min read

How To Install And Manage Desktop Apps On Mac OS With Ansible And Homebrew Scripts

What is Homebrew or Brew for Mac operating systems? Homebrew is a free and open-source package manager for Mac OS systems that allows you to install and update apps. In this tutorial, we are going to use Homebrew with Ansible to automate and track our Mac app installations.

How To Install And Manage Desktop Apps On Mac OS With Ansible And Homebrew Scripts
Homebrew And Ansible
Table of Contents

A couple of days ago a created an Ansible and Chocolatey article to automate desktop app installations on Windows systems. To be fair I have to do the same with Mac OS and Homebrew. What is Homebrew or Brew for Mac operating systems? Homebrew is a free and open-source package manager for Mac OS systems that allows you to install and update apps. In this tutorial, we are going to use Homebrew with Ansible to automate and track our Mac app installations.

Prerequisite Initial Steps

The initial steps would be to have Ansible set up already and Homebrew installed on your Mac OS machine such as your MacBook or Mac Mini. You can follow the tutorials below to set up Ansible and install Homebrew:

How To Set Up Ansible Inside A Github Repository And Automate Your Workloads
Ansible is an open-source configuration management and IT automation platform. Let’s jump in and set up our Ansible Github repository and run an example automation playbook.
Homebrew
The Missing Package Manager for macOS (or Linux).

Create And Set Up Brew Ansible Directory

After setting up Brew and Ansible I created a local folder and named it macos-ansible however you can name the directory any name that you find suitable. I added a playbooks directory to store the following two playbooks - mac_apps.yml and upgrade_homebrew. Copy the playbooks below and add them to your playbooks directory.

Ansible Directory For Homebrew

upgrade_homebrew.yml

This ansible playbook will update and upgrade all your apps installed with homebrew including updating the package manager version if a new version is released.

#upgrade_homebrew.yml
## upgrade macos apps with homebrew
---
- hosts: local
  vars_files:
    - ../vars.yml

  tasks:
    - name: Upgrade All Mac Apps
      community.general.homebrew_cask:
        update_homebrew: true
        upgrade_all: true

mac_apps.yml

This ansible-playbook will install, update or remove apps from your Mac OS system. Browse through the packages/applications available on brew.sh and update this playbook according to the applications you want to install and keep track of on your Mac OS system. In the example below I am installing three applications on my Macbook. Run the following command from the CLI to execute this playbook - ansible-playbook playbooks/mac_apps.yml --ask-pass it will prompt you for your Mac OS password and then execute the workflow and install or update all of the apps defined in the playbook.

#mac_apps.yml
##macos apps
---
- hosts: localhost
  vars_files:
    - ../vars.yml

  tasks:
    - name: Install/Uninstall/Update WhatsApp
      community.general.homebrew_cask:
        name: whatsapp
        path: /Users/username/Applications
        state: present

    - name: Install/Uninstall/Update Slack
      community.general.homebrew_cask:
        name: slack
        path: /Users/username/Applications
        state: present

    - name: Install/Uninstall/Update Office365
      community.general.homebrew_cask:
        name: microsoft-office-businesspro
        path: /Users/username/Applications
        state: present

Once complete navigate to the applications directory on your Mac and verify that your applications were installed.

Conclusion

In conclusion, Homebrew is an awesome open-source package manager for Mac OS systems and has large community support behind it. If you enjoyed this article consider signing up for our newsletter and don't forget to share it with people that would find it useful. Leave a comment below with a tutorial you would like us to cover.

Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to Opensource Geeks.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.