Ansible — Inventory Managment

In this series of blog posts, I will be talking about Ansible. Ansible is a powerful automation tool that you can learn quickly.

When using Ansible, I have been constantly uneasy about how inventory is managed. If you feel the same, in this article I will try to explain how I structure my inventories and where I think it could be improved.

The Ansible documentation recommends to put servers in groups by type, like so: [webservers] [dbservers]

In your playbook you can then target specific parts to one group. For example your webservers will have different packages compared to your db servers. It also allows you to limit deployment to one group. For example with the –limit flag you can limit your deployment to just the dbservers.

An alternative approach I have been taking is to create seperate inventories for each environment. Like Production, UAT and Testing. For each environment I create an inventory like so:

[webservers] [dbservers]


[webservers] [dbservers]

This means that when I run my Ansible command, I have a separate command for each environment. This means there is less of a chance of deploying to the wrong servers and I can deploy an entire environment all at once easily. Those commands would look like this:

ansible-playbook rails_stack.yml -i uatansible-playbook rails_stack.yml -i prod

The Ansible best practices document recommends this as well and naming your groups based on their location (data center).

Originally published at

I enjoy building software, making web applications, surfing, snowboarding and cooking!