What is Ansible?
The elevator pitch for Ansible is that it’s an automation engine, not unlike Puppet and Chef. However, Ansible doesn’t require the use of any agents on the target machines. Which is always appealing to IT folks, because not only are we automating and making things consistent, we’re also taking away administrative headaches by not installing more agents. You can read more about Ansible here, but I’m really going to concentrate on Inventory Files in this blog.
Why We Need Inventory Files
Ansible can be used in multiple ways to automate configurations on many objects that might live in our data centers like servers, networking devices, storage devices, security, etc. It would be ridiculous to have to type in which objects we want Ansible to configure every time we want to use it, though. So we create Inventory Files which are basically text files that contain the devices in our data centers and groups them to make it even easier to run tasks against.
Let’s see an example:
This is a really easy example, but we can build that out by adding some simple host names at the beginning.
We can also create groups now.
#Here are the groups
#And even groups of groups by using the :children syntax
As shown above creating groups is pretty easy. It’s also good to know that devices/servers can belong to multiple groups. It makes sense because you might have a data base server that belongs to [db_servers] but it also belongs to [windows_servers]. That way we can easily update database applications using the db group, but also patch the OS using the Windows group, just as a simple use case example.
Not only do these inventory files contain the devices, but their host names, how to connect to them (for example via SSH) and usernames and passwords. Adding this information is done through the use of Inventory Paramaters. These are absolutely necessary because it tells the Ansible Controller how to communicate with the various devices. Some examples of inventory paramaters are: ansible_port, ansible_password, and ansible_connection. I’ll show some common ones in examples.
When we first specify our devices as I did above with
this is where we can include more information using inventory parameters. For example, if this is a Linux server, I’ll want to connect to it using SSH.
web1 ansible_host=web1.malhoit.com ansible_connection=ssh ansible_port=22
If this were a Windows server, the inventory parameter would be:
web1 ansible_host=web1.malhoit.com ansible_connection=winrm
We can also add usernames and passwords and all sorts of other parameters as listed here.
web1 ansible_host=web1.malhoit.com ansible_connection=ssh ansible_port=22 ansible_user=lauren ansible_ssh_pass=password
Every parameter is simply separated with a space.
I’ll continue to go deeper on these topics over the next several weeks. As always, no egos here. Please let me know if you have any constructive criticism @malhoit.