Setting up Ansible on macOS is straightforward with multiple installation options. Current stable version: Ansible-core 2.20.2 (released January 29, 2026)
Before installing Ansible, ensure your system meets the following requirements:
Before installing Ansible, install the Xcode Command Line Tools:
xcode-select --install
Follow the prompts to install the tools.
Multiple installation methods are available depending on your needs:
If you don’t have Homebrew installed, install it first:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
After installing Homebrew, update it:
brew update
Then install Ansible:
brew install ansible
# Install pip if not already installed
python3 -m ensurepip --upgrade
# Create a virtual environment (recommended)
python3 -m venv ansible-env
source ansible-env/bin/activate
pip install --upgrade pip
pip install ansible
# To activate the environment in future sessions:
# source ansible-env/bin/activate
# Install pipx
brew install pipx
# Or: python3 -m pip install --user pipx
# Install and run Ansible with pipx
pipx install ansible
Check the Ansible version to confirm the installation was successful:
ansible --version
You should see output similar to:
ansible [core 2.20.2]
config file = /etc/ansible/ansible.cfg
configured module search path = ['/Users/username/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /path/to/ansible/lib/python3.x/site-packages/ansible
executable location = /path/to/ansible/bin/ansible
python version = 3.12.x
Ansible uses SSH to manage remote machines, so you’ll need to configure passwordless SSH access to the machines you want to manage:
Generate an SSH key (if you don’t already have one):
ssh-keygen -t rsa -b 4096 -C "ansible@macos-control"
# Press Enter to accept defaults, optionally set a passphrase
Copy the SSH key to the remote machines:
Use ssh-copy-id to copy your SSH public key to the remote server:
ssh-copy-id user@remote_server_ip
# If ssh-copy-id is not available, use:
cat ~/.ssh/id_rsa.pub | ssh user@remote_server_ip "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"
Test SSH connection:
ssh user@remote_server_ip
Ansible uses an inventory file to define the remote hosts you want to manage. You can create a simple inventory file on your Mac.
Create a directory for your Ansible configuration:
mkdir -p ~/ansible
cd ~/ansible
Create an inventory file:
nano inventory
Add remote hosts in this format:
[webservers]
web1.example.com ansible_host=192.168.1.10
web2.example.com ansible_host=192.168.1.11
[databases]
db1.example.com ansible_host=192.168.1.20
db2.example.com ansible_host=192.168.1.21
[production:children]
webservers
databases
[all:vars]
ansible_user=ansible_user
ansible_ssh_private_key_file=~/.ssh/id_rsa
ansible_python_interpreter=/usr/bin/python3
Create a custom ansible.cfg file to override default settings:
# Create ansible.cfg in your project directory
cat > ~/ansible/ansible.cfg << EOF
[defaults]
inventory = ~/ansible/inventory
remote_user = ansible_user
host_key_checking = False
gathering = smart
fact_caching = memory
timeout = 30
forks = 20
stdout_callback = yaml
interpreter_python = auto_silent
[inventory]
enable_plugins = host_list, script, auto, yaml, ini, toml
[privilege_escalation]
become = True
become_method = sudo
become_user = root
[ssh_connection]
ssh_args = -o ControlMaster=auto -o ControlPersist=60s
pipelining = True
EOF
You can now test if Ansible is set up correctly by pinging your remote servers:
# Test with specified inventory
ansible all -i ~/ansible/inventory -m ping
# Test with default inventory (if configured in ansible.cfg)
ansible all -m ping
# Test specific group
ansible webservers -i ~/ansible/inventory -m ping
# Test specific host
ansible web1.example.com -i ~/ansible/inventory -m ping
This command uses the ping module to test connectivity to all the hosts defined in the inventory file.
Ansible Collections are a distribution format that packages Ansible content. Install commonly used collections:
# Install community collections
ansible-galaxy collection install community.general
ansible-galaxy collection install community.docker
ansible-galaxy collection install ansible.posix
# Install cloud provider collections
ansible-galaxy collection install amazon.aws
ansible-galaxy collection install azure.azcollection
ansible-galaxy collection install google.cloud
chmod 600 ~/.ssh/id_rsa)echo $PATHOnce Ansible is working, you can:
Any questions?
Feel free to contact us. Find all contact information on our contact page.