Risan Bagja

Hello Ansible

Installation on macOS

Ansible required Python 2.x version to run, so if you’re using the latest Python 3.x version switch it first. If you are using Pyenv to manage the Python versions, simply set the PYENV_VERSION within your .zshrc or any other shell configuration file.

export PYENV_VERSION=2.7.13

And don’t forget to source your .zshrc file. Now simply install the Ansible using Homebrew:

$ brew install sensible

Ansible Hosts File

Ansible hosts file is a list of your target machines.

$ mkdir /usr/local/etc/ansible
$ vim /usr/local/etc/ansible/hosts

It can be an IP address, a domain name, or even a subdomain:

162.243.175.31
risanbagja.com
server.risanbagja.com

If you change the default SSH port, you must specify the port within the hosts file:

162.243.175.31:2222

Ping All The Hosts

To ping all the hosts use the following commands:

$ ansible all -m ping

Arguments explanation:

You can also specify the user with -u option:

$ ansible all -m ping -u john

You can also use the sudo with --become-method option:

$ ansible all -m ping --become-method=sudo -K

The -K or --ask-become-pass option is for prompting password.

Hello World Ansible

Here’s the command to print “Hello World” on your target machine

$ ansible all -a "/bin/echo Hello World"

The -a option is for module arguments.