Though I know it’s not ideal, I am running an older version of Mac OS Sierra (version 10.12) on a 2011 Mac Book Pro. Both the operating system and the laptop have long since been rendered obsolete by Apple, but since I have a lot of attachment to things that have worked in the past, I have not yet replaced the laptop.

Macbook Pro Early 2011

For many years, I have been using Homebrew to manage packages (especially open source ones) on this laptop. Prior to writing this tutorial, I had installed Ansible via Homebrew, and for quite a while upgrading it was a cinch, but recently, when trying to upgrade it to the latest version (version 5.0.1 at the time of writing), Homebrew attempted to install additional packages - one of which is the compiler for the Rust programming language as a dependency for Ansible to work. To be honest, for older Mac OS versions, Homebrew will show a disclaimer warning the user that installing some packages will fail due to issues during the build process. This is due to the fact that for older Mac OS versions, Homebrew will not have ready to install (pre-built packages), and thus will attempt to build all packages to be installed from scratch, thus greatly lengthening the install process. Unfortunately for me, as forewarned by Homebrew, the installation of Rust failed, and Homebrew printed a very long error message shown below:

Install/Upgrade Ansible on Mac OS (via Homebrew)

brew install ansible

Build Error:

==> Installing dependencies for ansible: rust

Running `brew update --preinstall`...
==> Auto-updated Homebrew!
Updated 2 taps (homebrew/cask and homebrew/core).
==> Updated Formulae
Updated 1 formula.
==> Updated Casks
Updated 3 casks.

Warning: You are using macOS 10.12.
We (and Apple) do not provide support for this old version.
You will encounter build failures with some formulae.
Please create pull requests instead of asking for help on Homebrew's GitHub,
Twitter or any other official channels. You are responsible for resolving
any issues you experience while you are running this
old version.

==> Cloning https://github.com/rust-lang/cargo.git
Updating /Users/adminaccount/Library/Caches/Homebrew/rust--cargo--git
==> Checking out tag 0.57.0
HEAD is now at 4ed5d137b Auto merge of #9958 - ehuss:1.56-backports, r=alexcrichton
HEAD is now at 4ed5d137b Auto merge of #9958 - ehuss:1.56-backports, r=alexcrichton
==> Downloading https://static.rust-lang.org/dist/2021-09-09/cargo-1.55.0-x86_64-apple-darwin.tar.gz
Already downloaded: /Users/adminaccount/Library/Caches/Homebrew/downloads/7015266fc10b43cb834cb2e7953148e6c82274ceaf714e8424c76643a87edf5e--cargo-1.55.0-x86_64-apple-darwin.tar.gz
==> Downloading https://static.rust-lang.org/dist/rustc-1.56.1-src.tar.gz
Already downloaded: /Users/adminaccount/Library/Caches/Homebrew/downloads/304ecd8cb78139e64bb1b5245505b74d6f06874524edbc36986d7fc0dd5c6d13--rustc-1.56.1-src.tar.gz
==> Downloading https://github.com/rust-lang/rustup/archive/1.24.3.tar.gz
==> Downloading from https://codeload.github.com/rust-lang/rustup/tar.gz/1.24.3
Warning: ignoring --capath, not supported by libcurl
######################################################################## 100.0%
==> Installing dependencies for rustup-init: rust
==> Installing rustup-init dependency: rust
==> ./configure --prefix=/usr/local/Cellar/rust/1.56.1 --release-channel=stable
==> make
Last 15 lines from /Users/adminaccount/Library/Logs/Homebrew/rust/02.make:
  CRATE_CC_NO_DEFAULTS = None
  running: "clang" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "--target=x86_64-apple-darwin" "-ffunction-sections" "-fdata-sections" "-fPIC" "--target=x86_64-apple-darwin" "-stdlib=libc++" "-fno-builtin" "-fvisibility=hidden" "-ffreestanding" "-DVISIBILITY_HIDDEN" "-o" "/private/tmp/rust-20211220-3496-1re27mu/rustc-1.56.1-src/build/x86_64-apple-darwin/stage0-std/x86_64-apple-darwin/release/build/compiler_builtins-f4f725de89941efa/out/absvdi2.o" "-c" "/private/tmp/rust-20211220-3496-1re27mu/rustc-1.56.1-src/src/llvm-project/compiler-rt/lib/builtins/absvdi2.c"
  cargo:warning=clang: error: invalid deployment target for -stdlib=libc++ (requires OS X 10.7 or later)
  exit status: 1

  --- stderr


  error occurred: Command "clang" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "--target=x86_64-apple-darwin" "-ffunction-sections" "-fdata-sections" "-fPIC" "--target=x86_64-apple-darwin" "-stdlib=libc++" "-fno-builtin" "-fvisibility=hidden" "-ffreestanding" "-DVISIBILITY_HIDDEN" "-o" "/private/tmp/rust-20211220-3496-1re27mu/rustc-1.56.1-src/build/x86_64-apple-darwin/stage0-std/x86_64-apple-darwin/release/build/compiler_builtins-f4f725de89941efa/out/absvdi2.o" "-c" "/private/tmp/rust-20211220-3496-1re27mu/rustc-1.56.1-src/src/llvm-project/compiler-rt/lib/builtins/absvdi2.c" with args "clang" did not execute successfully (status code exit status: 1).


warning: build failed, waiting for other jobs to finish...
error: build failed
Build completed unsuccessfully in 0:04:39
make: *** [all] Error 1

Do not report this issue to Homebrew/brew or Homebrew/core!

These open issues may also help:
rust-analyzer 2021-12-13 https://github.com/Homebrew/homebrew-core/pull/91289
rust 1.57.0 + apply patch to fix duplicate object file bug https://github.com/Homebrew/homebrew-core/pull/90103
Rust-dependent formulae on Apple Silicon - upstream issue tracker https://github.com/Homebrew/homebrew-core/issues/68301

Error: You are using macOS 10.12.
We (and Apple) do not provide support for this old version.
You will encounter build failures with some formulae.
Please create pull requests instead of asking for help on Homebrew's GitHub,
Twitter or any other official channels. You are responsible for resolving
any issues you experience while you are running this
old version.

At this point, rather than crying over spilt milk, I resolved to try a different approach. I decided to install Ansible via pip. Here are the steps on how to do so on Mac OS 10.12:

Pre-Requisites

  • python3
  • pip3

Install Ansible via Pip3

python3 -m pip install --user ansible

NB: This will install ansible for the current user only

Confirm if Ansible is installed correctly

pip3 list

Output:

Package      Version
------------ -------
ansible      5.0.1
ansible-core 2.12.1
cffi         1.15.0
cryptography 36.0.1
Jinja2       3.0.3
MarkupSafe   2.0.1
packaging    21.3
pip          21.3.1
pycparser    2.21
pyparsing    3.0.6
PyYAML       6.0
resolvelib   0.5.4
setuptools   59.0.1
wheel        0.37.0

As shown above, Ansible 5.0.1 has been installed, but in order to run it from the terminal, some additional steps need to be taken. Since Ansible was installed by the current user, we will start by finding the installation directory by calling python3’s site module (as a script) and passing the –user-base flag to find the directory used to store user installed modules.

Find the Ansible installation directory

python3 -m site --user-base

Output: Here’s the output from my terminal (yours should be similar):

/Users/izo/Library/Python/3.9

Ansible by default is installed by pip3 in the bin directory. To check, run:

ls -al ~/Library/Python/3.9/bin/

Output:

total 184
drwxr-xr-x  13 izo  staff   442B Dec 21 12:00 .
drwx------   4 izo  staff   136B Dec 21 12:00 ..
-rwxr-xr-x   1 izo  staff   5.8K Dec 21 12:00 ansible
-rwxr-xr-x   1 izo  staff   5.8K Dec 21 12:00 ansible-config
-rwxr-xr-x   1 izo  staff    13K Dec 21 12:00 ansible-connection
-rwxr-xr-x   1 izo  staff   5.8K Dec 21 12:00 ansible-console
-rwxr-xr-x   1 izo  staff   5.8K Dec 21 12:00 ansible-doc
-rwxr-xr-x   1 izo  staff   5.8K Dec 21 12:00 ansible-galaxy
-rwxr-xr-x   1 izo  staff   5.8K Dec 21 12:00 ansible-inventory
-rwxr-xr-x   1 izo  staff   5.8K Dec 21 12:00 ansible-playbook
-rwxr-xr-x   1 izo  staff   5.8K Dec 21 12:00 ansible-pull
-rwxr-xr-x   1 izo  staff   1.5K Dec 21 12:00 ansible-test
-rwxr-xr-x   1 izo  staff   5.8K Dec 21 12:00 ansible-vault

As shown above, the Ansible binary is the first file listed above. In order to run it from the terminal:

Add an entry to your .profile

As usual, I am using vim as my preferred text editor.

vi ~/.profile

Add the following to the bottom:

# Run packages installed via Pip3
export PATH="$PATH:$HOME/Library/Python/3.9/bin"

Reload your profile settings

source ~/.profile

Now you should be able to run Ansible via the terminal. In order to check:

ansible --version

Output

ansible [core 2.12.1]
  config file = None
  configured module search path = ['/Users/izo/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /Users/izo/Library/Python/3.9/lib/python/site-packages/ansible
  ansible collection location = /Users/izo/.ansible/collections:/usr/share/ansible/collections
  executable location = /Users/izo/Library/Python/3.9/bin/ansible
  python version = 3.9.9 (main, Dec 19 2021, 23:23:02) [Clang 9.0.0 (clang-900.0.39.2)]
  jinja version = 3.0.3
  libyaml = True
ansible-vault --version

Ansible Vault Version Output

ansible-vault [core 2.12.1]
  config file = None
  configured module search path = ['/Users/izo/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /Users/izo/Library/Python/3.9/lib/python/site-packages/ansible
  ansible collection location = /Users/izo/.ansible/collections:/usr/share/ansible/collections
  executable location = /Users/izo/Library/Python/3.9/bin/ansible-vault
  python version = 3.9.9 (main, Dec 19 2021, 23:23:02) [Clang 9.0.0 (clang-900.0.39.2)]
  jinja version = 3.0.3
  libyaml = True

Upgrading Ansible

To upgrade ansible, run:

pip3 install --upgrade ansible