Getting started with Ansible

Ansible is not hard to use, nor complicated to setup.
It can be setup from scratch rather fast.
You only need one server where Ansible is installed, and preferably many hosts to connect to.
Below the very basic to start.

On the Ansible server, run:

apt update
apt install ansible

That’s it for the installation! Now that was easy.
We also need a private key to connect to the hosts.
To create a key, run:

ssh-keygen -t rsa -b 4096

Leave the passphrase blank

Now type:

cat /root/.ssh/id_rsa.pub

and add this key to your hosts

echo “the-output-of-the-above-command” >> /root/.ssh/authorized_keys

We need to tell Ansible to start using this key file by default. This can be done by modifying the /etc/ansible/ansible.cfg file.
Edit the file using your favorite editor and change the private_key_file value accordingly

# if set, always use this private key file for authentication, same as
# if passing –private-key to ansible or ansible-playbook
private_key_file = /root/.ssh/id_rsa

Save and exit.
We need hosts to connect to. These are saved in file /etc/ansible/hosts
Edit this file using your favorite editor and add some servers in a group, as shown below.

[SomeServers]
10.81.70.62
10.81.70.63
10.81.70.64
10.81.70.65
10.81.70.66

Save and exit.
Time to test!

Run: ansible SomeServers -m ping

Done. Hurray! 🙂

You may also like...