How to install Ansible on Apple MacOS X using command line
How do I install the Ansible software to automate apps and IT infrastructure from my Apple Macbook pro running MacOS X?
Ansible is the simplest and easy to use software to automate apps and IT infrastructure. You can use Ansible for application deployment, configuration management, continuous delivery and many sysadmin related tasks.
Install Ansible on MacOS using brew command
Open the terminal app and type the following command: $ brew install ansible Sample outputs:
Your Macbook pro now act as a master node or control system.
Creating inventory hosts file
Ansible needs to know which servers to connect to and manage those boxes. You need to define or create Ansible’s inventory hosts file. The file contains a list, options, and groups for your servers. Its default location is /usr/local/etc/ansible/hosts on MacOS X. You can edit the file /usr/local/etc/ansible/hosts or create ~/hosts file: $ vi ~/hosts Here is my sample file:
Save and close the file. Make sure you install the ssh keys in box1 and 192.168.2.15 servers. If you don’t have the ssh key on your MacOS X, generate the ssh key on the master node (MacOS X): $ ssh-keygen -t rsa -C "OS X laptop ssh key" Install the ssh key: $ ssh-copy-id -i ~/.ssh/id_rsa.pub box1 $ ssh-copy-id -i ~/.ssh/id_rsa.pub 192.168.2.15 Test the connectivity: $ ansible all --inventory-file=~/hosts -m ping Sample outputs:
You can set ANSIBLE_HOSTS to define your ~/hosts file: $ export ANSIBLE_HOSTS=~/hosts $ echo 'export ANSIBLE_HOSTS=~/hosts' >> ~/.bashrc $ ansible all -m ping ## let us run uptime command all hosts ## $ ansible all -a 'uptime' Sample outputs:
The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.