Skip to content

Instantly share code, notes, and snippets.

@headmin
Created March 17, 2023 14:19
Show Gist options
  • Save headmin/e52989c738a0f01b35c0f782f6307000 to your computer and use it in GitHub Desktop.
Save headmin/e52989c738a0f01b35c0f782f6307000 to your computer and use it in GitHub Desktop.

How to install Ansible and Python on macOS - simply in minutes

Here we are going to install the latest Python (3.11.2 as of this writing) and Ansible on macOS Ventura in the most clever and simplistic way. All artifacts are installed in user and not system context.

How does it work? The awesome asdf-vm project is designed for version management of developer runtimes. Here we use a small feature to also directly install default-python-packages and pick Ansible as our choice (could be pipenv or others).

Some features here have been presented in my talk "Runtime and tools – version management on macOS" at the MDO:YVR 2022 conference.

Requirements

  • macOS 12 or macOS 13
  • asdf dependencies (via homebrew) as listed here

Install Python 3.11.2 and Ansible in one go.

## add asdf 
git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.11.2

## edit zsh conf 
nano ~/.zshrc

## add  `. "$HOME/.asdf/asdf.sh"`
. "$HOME/.asdf/asdf.sh"

## activate 
source ~/.zshrc

## add ansible to "default-python-packages" 
echo ansible > $HOME/.default-python-packages

## install Python plugin 
asdf plugin add python

## install latest python 
asdf install python latest

## set global 
asdf global python latest
## check Python version 
python --version

## check Ansible version 
ansible --version

More info about asdf

You find more info about asdf here on this blog post. Macadmins can join the #asdf channel on macadmins-slack.

@headmin
Copy link
Author

headmin commented Mar 17, 2023

The result

jappleseed@macOS ~ % python --version
Python 3.11.2
jappleseed@macOS ~ % ansible --version
ansible [core 2.14.3]
  config file = None
  configured module search path = ['/Users/jappleseed/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /Users/jappleseed/.asdf/installs/python/3.11.2/lib/python3.11/site-packages/ansible
  ansible collection location = /Users/jappleseed/.ansible/collections:/usr/share/ansible/collections
  executable location = /Users/jappleseed/.asdf/installs/python/3.11.2/bin/ansible
  python version = 3.11.2 (main, Mar 17 2023, 14:13:31) [Clang 14.0.0 (clang-1400.0.29.202)] (/Users/jappleseed/.asdf/installs/python/3.11.2/bin/python3.11)
  jinja version = 3.1.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment