Red Hat Ansible
I’ve finally made time to go through a couple more Ansible books and online courses. Have been using Ansible for more than a year but this time I’ll make it into a number of Unix Tutorial projects to automate as much of my home office setup and online/cloud infrastructure for my consultancy Tech Stack Solutions as possible.
Following the official documentation from docs.ansible.com, these are the commands to install Ansible on most Ubuntu systems:
I have created the following basic file for now. This is a newer format of the hosts inventory file, YAML – much more structured and easy to read:
As you remember, becky is one of my Raspberry Pi systems. 192.168.1.66 is the primary IP it has on my local network, and 202 is the SSH port – even though it’s an internal system not accessible from Internet, I still don’t like using default SSH port 22.
I simply created
/home/greys/proj/ansible folder, there will be opportunities to refactor it later.
Let’s try listing hosts that Ansible knows about:
Nothing! You want to know why? Because we need to tell Ansible about the inventory file we just created (by default it only knows about system-wide /etc/ansible/hosts file, but I intentionally don’t use it).
We need to create a basic Ansible config file which will specify the new location of my inventory file.
What I actually did this time is copied global ansible config from /etc/ansible/ansible.cfg to my project directory, and then changed the inventory setting in it with vim editor:
I changed the following in it:
If you want to start fresh, you can skip the copying command and simply create new
ansible.cfg in your directory, with just the following:
Anyway, with this config file created and hosts file location updated, we can re-try the same host listing command. And this time it works!
Just like ping command tests basic connectivity in common network troubleshooting, Ansible has ping command to confirm that it has sufficient access to each host for further management. Ansible ping is essentially an SSH attempt:
This is expected on my Ubuntu XPS 13 laptop, because I haven’t setup passwordless SSH access from it to my other servers yet.
This means I need to deploy my XPS 13 public SSH key onto becky host using my SSH password, and then try again:
Now try logging into the machine, with: “ssh -p ‘202’ ‘192.168.1.66’” and check to make sure that only the key(s) you wanted were added.
All done, now let’s re-run Ansible ping: