English translation
This is an example INI-format Inventory file
AI Article Decision Snapshot
Turn the lesson into workflow, model, budget, and security checks before choosing tools.
Use this quick snapshot before leaving the article. It keeps the next search tied to practical AI software, model/API, cost, privacy, and implementation questions.
Workflow fit
Identify the real job behind the article: coding, research, document review, support, analytics, content, or internal automation.
Model or tool decision
Decide whether the next step is a software shortlist, an AI tool comparison, an API platform choice, or a model benchmark.
Budget and usage signal
Estimate seats, API calls, prompt volume, retries, review time, and fallback work before assuming the workflow is cheap.
Security and privacy review
Check whether source code, customer data, private documents, prompts, logs, or embeddings will enter the AI workflow.
In the previous article, we discussed the fundamental concepts of Play and Playbook, learning how to define a set of automated tasks and apply them to specified target hosts. In this article, we delve into the format of the Inventory file—a critical component in Ansible responsible for defining managed hosts and their groupings.
What Is an Inventory File?
In Ansible, an Inventory file is a host inventory that describes which hosts will be managed and how those hosts are organized into distinct groups. An inventory can be either a static text file or dynamically generated, and supports multiple formats.
When executing tasks, Ansible determines the scope of operation based on the hosts and groups defined in the Inventory file. Therefore, understanding and correctly using the Inventory file forms the foundation of automated operations.
Basic Inventory File Formats
Ansible supports two primary Inventory file formats: INI format and YAML format. Below, we detail each.
INI Format
The INI format is the most commonly used Inventory format in Ansible. Its basic structure is as follows:
# This is an example INI-format Inventory file
[webservers]
web1.example.com
web2.example.com
[dbservers]
db1.example.com
db2.example.com
[all:vars]
ansible_user=your_user
ansible_ssh_private_key_file=/path/to/your/private/key
Explanation:
#denotes comments.[webservers]and[dbservers]are group names.- Each group lists its member hosts underneath.
- Variables defined under
[all:vars]apply globally to all hosts.
YAML Format
In addition to INI, Ansible also supports YAML-formatted Inventory files. Here's an example:
# This is an example YAML-format Inventory file
all:
children:
webservers:
hosts:
web1.example.com:
web2.example.com:
dbservers:
hosts:
db1.example.com:
db2.example.com:
vars:
ansible_user: your_user
ansible_ssh_private_key_file: /path/to/your/private/key
Explanation:
allis the top-level dictionary.childrendefines nested subgroups.hostslists individual hosts.varsdefines variables scoped to the group.
Advanced Inventory Usage
Beyond simple host and group definitions, the Inventory file offers several features to handle complex scenarios.
Nested Host Groups
You can include subgroups within a group—for example:
[all:children]
webservers
dbservers
[frontend]
web1.example.com
web2.example.com
[backend]
db1.example.com
db2.example.com
In this example, frontend and backend can be used independently as host groups—or collectively via all.
Dynamic Inventory
For large-scale systems, manually maintaining an Inventory file becomes impractical. Dynamic inventory solves this by generating up-to-date host lists from external data sources—such as cloud provider APIs.
For instance, AWS dynamic inventory scripts automatically fetch running EC2 instances and register them as hosts in Ansible.
Variable Definitions
Variables can be defined for specific hosts or groups directly in the Inventory. Here’s an example defining group-scoped variables:
[webservers]
web1.example.com
web2.example.com
[webservers:vars]
http_port=80
In this case, the http_port variable is available to any Playbook targeting the webservers group.
Summary
In this article, we thoroughly examined the Inventory file format in Ansible—including both INI and YAML syntax—and explored how host grouping and variable assignment enable effective server management. The Inventory file is foundational to Ansible; mastering it is essential.
In the next article, we’ll explore key related concepts—variables and facts—to further enhance our automation capabilities.
Apply This Lesson
Turn this article into AI software, model, API, and security decisions.
English Article FAQ
Use this article as evidence before choosing AI tools
How should I use this AI Tutorials article?
Use it as the implementation or learning layer, then connect the idea to AI software buyer guides, tool comparisons, benchmarks, API choices, and security checks before making a production decision.
Is this English article different from the Chinese original?
The English edition is localized for global AI readers while preserving the original diagrams, screenshots, prompts, code examples, and source context from the Chinese article.
What should I read after This is an example INI-format Inventory file?
Continue with AI Software Buyer Guides, AI Tools Workbench, Best AI Coding Agents, AI Model Benchmarks, OpenAI vs Anthropic API, or LLM Security Tools depending on the decision you need to make.
Can this article alone choose an AI product or model?
No. Treat the article as evidence and context, then validate fit with pricing, privacy requirements, integration effort, benchmark results, workflow tests, and fallback planning.
Continue