Search⌘ K
AI Features

Solution: Writing an Inventory

Explore how to write a structured Ansible inventory file that groups different server types like databases, load balancers, and web servers. Understand the role of groups and hosts in organizing infrastructure to streamline configuration and automation tasks.

We'll cover the following...

Solution

Shell
[all]
dbservers
loadbalancers
redis
kafka
webservers
grafana
backup
[dbserver1]
dbserver1.ourcompany.com ansible_host=192.168.1.1 ansible_user=username ansible_password=****
[dbserver2]
dbserver2.ourcompany.com ansible_host=192.168.1.2 ansible_user=username ansible_password=****
[dbserver3]
dbserver3.ourcompany.com ansible_host=192.168.1.3 ansible_user=username ansible_password=****
[lb1]
lb1.ourcompany.com ansible_host=192.168.1.4 ansible_user=username ansible_password=****
[lb2]
lb2.ourcompany.com ansible_host=192.168.1.5 ansible_user=username ansible_password=****
[lb3]
lb3.ourcompany.com ansible_host=192.168.1.6 ansible_user=username ansible_password=****
[redis1]
redis1.ourcompany.com ansible_host=192.168.1.7 ansible_user=username ansible_password=****
[redis2]
redis2.ourcompany.com ansible_host=192.168.1.8 ansible_user=username ansible_password=****
[kafka1]
kafka1.ourcompany.com ansible_host=192.168.1.9 ansible_user=username ansible_password=****
[kafka2]
kafka2.ourcompany.com ansible_host=192.168.1.10 ansible_user=username ansible_password=****
[webserver1]
webserver1.ourcompany.com ansible_host=192.168.1.11 ansible_user=username ansible_password=****
[webserver2]
webserver2.ourcompany.com ansible_host=192.168.1.12 ansible_user=username ansible_password=****
[webserver3]
webserver1.ourcompany.com ansible_host=192.168.1.13 ansible_user=username ansible_password=****
[grafana1]
grafana1.ourcompany.com ansible_host=192.168.1.14 ansible_user=username ansible_password=****
[backup1]
backup1.ourcompany.com ansible_host=192.168.1.15 ansible_user=username ansible_password=****
[dbservers]
dbserver1
dbserver2
dbserver3
[loadbalancers]
lb1
lb2
lb3
[redis]
redis1
redis2
[kafka]
kafka1
kafka2
[grafana]
grafana1
[backup]
backup1
[apache_servers]
webserver1
webserver2
[nginx_servers]
webserver3
[webservers]
apache_servers
nginx_servers
...