Please enable JavaScript.
Coggle requires JavaScript to display documents.
Phase 2 - Ansible Inventory Management (Enterprise Level) - Coggle Diagram
Phase 2 - Ansible Inventory Management (Enterprise Level)
Inventory Management
Definition
What is an Inventory
Database of all managed servers
Tells Ansible where servers are located
Tells Ansible how to connect
Organizes infrastructure
Defines variables for servers
Purpose
Server organization
Automation target selection
Environment separation
Variable management
Enterprise scalability
Inventory Types
Static Inventory
Definition
Manually created inventory file
Stored locally
Administrator updates manually
File Formats
INI Format
YAML Format
Enterprise Use Cases
Small environments
Test labs
Development
Stable infrastructure
Advantages
Simple
Easy to understand
Easy troubleshooting
Disadvantages
Manual updates
Difficult for cloud environments
Dynamic Inventory
Definition
Automatically discovers servers
Data Sources
Amazon Web Services EC2
Microsoft Azure
Google Cloud Platform
VMware vCenter
OpenStack
Kubernetes
Red Hat Satellite
Cobbler
Service Discovery
Configuration Management Database (CMDB)
Inventory Plugins
Amazon EC2 Plugin
VMware Plugin
Kubernetes Plugin
OpenStack Plugin
Enterprise Benefits
Automatic server discovery
No manual inventory updates
Cloud scaling
High availability
Large enterprise environments
Commands
ansible-inventory --list
ansible-inventory --graph
ansible-inventory --host hostname
Inventory Directory Structure
inventory/
production/
hosts.ini
group_vars/
all.yml
webservers.yml
dbservers.yml
appservers.yml
host_vars/
web01.yml
db01.yml
staging/
hosts.ini
group_vars
host_vars
lab/
hosts.ini
group_vars
host_vars
Enterprise Environment Separation
Production
Live servers
Customer traffic
High security
Maintenance windows
Strict change management
Staging
Production replica
Final testing
User Acceptance Testing
Performance testing
Development
Developer environment
New feature testing
Frequent changes
Laboratory
Learning
Practice
Automation testing
Proof of Concept
Static Inventory File
Location
inventory/production/hosts.ini
INI Syntax
hostname
hostname ansible_host=192.168.1.10
hostname ansible_host=192.168.1.10 ansible_user=ansible
hostname ansible_host=192.168.1.10 ansible_port=22
hostname ansible_connection=ssh
Common Inventory Variables
ansible_host
Actual IP Address
ansible_user
Remote login user
ansible_port
SSH Port
ansible_connection
Connection type
ansible_password
Login password
ansible_become
Privilege escalation
ansible_become_user
Become another user
ansible_become_method
sudo
su
doas
ansible_python_interpreter
Python executable path
ansible_ssh_private_key_file
SSH key path
Host Groups
Definition
Collection of servers performing same function
Examples
Web Servers
Database Servers
Application Servers
Monitoring Servers
Load Balancers
DNS Servers
Backup Servers
Example
[webservers]
web01
web02
web03
[dbservers]
db01
db02
[appservers]
app01
app02
Benefits
Execute one playbook on multiple servers
Easier administration
Enterprise organization
Parent Groups
Definition
Group containing other groups
Example
[production:children]
webservers
dbservers
appservers
Enterprise Benefits
Run playbook against all production servers
Environment abstraction
Easier maintenance
Nested Groups
Multiple hierarchy
Linux
Web
Database
Monitoring
Windows
Domain Controllers
File Servers
SQL Servers
Variables
Definition
Store reusable information
Types
Inventory Variables
Group Variables
Host Variables
Playbook Variables
Extra Variables
Registered Variables
Facts
Variable Files
group_vars/
host_vars/
Example
group_vars/all.yml
ntp_server
dns_server
timezone
package_manager
group_vars/webservers.yml
http_port
nginx_worker_processes
document_root
host_vars/web01.yml
hostname
ip_address
ssl_certificate
group_vars Directory
Definition
Variables shared by entire group
Location
inventory/production/group_vars/
Common Files
all.yml
webservers.yml
dbservers.yml
appservers.yml
host_vars Directory
Definition
Variables unique to one server
Location
inventory/production/host_vars/
Example
web01.yml
db01.yml
Variable Precedence
Lowest Priority
Role Defaults
Inventory group_vars all.yml
Parent Group Variables
Child Group Variables
Host Variables
Playbook Variables
Task Variables
Extra Variables
Highest Priority
Group Priority
Definition
Determines which variable wins when multiple groups define same variable
Default Behavior
Child Group overrides Parent Group
Host Variables override Group Variables
Extra Variables override everything
Enterprise Example
all.yml
timezone UTC
webservers.yml
timezone Asia Riyadh
host_vars/web01.yml
timezone Asia Karachi
Final Result
Asia Karachi
Inventory Commands
Validate Inventory
ansible-inventory --list
Display Inventory Graph
ansible-inventory --graph
Display Host Information
ansible-inventory --host web01
Ping All Hosts
ansible all -m ping
Ping One Group
ansible webservers -m ping
Ping One Host
ansible web01 -m ping
List Hosts
ansible all --list-hosts
Show Variables
ansible-inventory --host web01
Enterprise Inventory Best Practices
Separate environments
Never mix Production and Laboratory
Use group_vars
Use host_vars only for unique settings
Prefer SSH Keys over passwords
Never hardcode passwords
Use Ansible Vault for secrets
Keep inventory inside Version Control
Maintain naming standards
Use meaningful group names
Keep inventory modular
Validate inventory before execution
Document every variable
Enterprise Naming Convention
Hostnames
web01
web02
db01
db02
app01
app02
lb01
mon01
Groups
webservers
dbservers
appservers
monitoring
loadbalancers
Linux Paths
/etc/ansible/hosts
Default inventory
/etc/ansible/ansible.cfg
Global configuration
project/
ansible.cfg
inventory/
production/
staging/
lab/
inventory/production/group_vars/
inventory/production/host_vars/
playbooks/
roles/
templates/
files/
Enterprise Workflow
Build Inventory
Create Host Groups
Create Parent Groups
Assign Variables
Separate Environments
Validate Inventory
Test Connectivity
Execute Playbooks
Verify Results
Generate Reports
Maintain Inventory
Enterprise Interview Questions
What is an inventory
Difference between Static and Dynamic Inventory
What are Host Groups
What are Parent Groups
What is group_vars
What is host_vars
What is Variable Precedence
What is Group Priority
Difference between group_vars and host_vars
How does Dynamic Inventory work
How do you validate inventory
How do you organize inventory in enterprise
What is the default inventory path
Why separate Production, Staging and Laboratory
Best practices for enterprise inventory management