Changing the Default Shell on macOS with Ansible

April 29 2018

macOS High Sierra ships with GNU bash, version 3.2.57(1)-release, a version line that dates back to 2006. The main Bash project has been on version 4 since 2009. It appears that licensing issues are behind why macOS ships with such an old version of Bash as default. But that doesn’t stop us from upgrading the Bash version ourselves.

Upgrading Via Homebrew and Ansible

The example below uses Homebrew and Ansible, but should be generally applicable to your favorite way of installing software and/or configuring macOS.

Install the latest available version of Bash:

This will use Homebrew to install the latest version of Bash. Substitute your favorite shell as needed.

- homebrew:
    name: bash
    state: present
    update_homebrew: yes

Change your user’s default shell

Under the hood, Ansible will use dscl to modify the user account and set the default shell. This superceeds all other ways of setting the default shells (including methods that work on other *nixes).

- user:
    name: {{ ansible_env.USER }}
    shell: /usr/local/bin/bash
become: yes