English translation
13. Basic Inventory Configuration in Ansible
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 explored how to use loops and conditional statements when writing Ansible Playbooks. In this article, we’ll dive deeper into Ansible Inventory files—specifically, how to configure basic static Inventory. Mastering Inventory configuration is essential for effectively managing and executing Ansible Playbooks.
What Is an Inventory?
In Ansible, an Inventory is a list used to define and organize your target hosts and their groupings. Ansible uses the Inventory to determine which hosts should execute a given task. You can use either a static Inventory file (typically in INI or YAML format) or a dynamic Inventory script.
Basic Static Inventory Configuration
A static Inventory is usually stored in a plain-text file, configurable using either simple INI or YAML syntax. Below, we demonstrate basic Inventory configuration through practical examples.
Example 1: INI-Format Inventory
Suppose you have three servers with IP addresses 192.168.1.10, 192.168.1.11, and 192.168.1.12. You can create a file named inventory.ini with the following content:
[web_servers]
web1 ansible_host=192.168.1.10
web2 ansible_host=192.168.1.11
[db_servers]
db1 ansible_host=192.168.1.12
In this example, we define two groups: web_servers and db_servers. The ansible_host keyword specifies the IP address of each host.
Example 2: YAML-Format Inventory
The same configuration can be expressed in YAML format by creating a file named inventory.yml:
all:
children:
web_servers:
hosts:
web1:
ansible_host: 192.168.1.10
web2:
ansible_host: 192.168.1.11
db_servers:
hosts:
db1:
ansible_host: 192.168.1.12
YAML’s hierarchical structure makes group–host relationships more explicit and easier to read.
Executing Ansible Commands Using an Inventory
Once your Inventory is configured, you can use the ansible command-line tool to run ad-hoc tasks. For instance, to ping all hosts in the web_servers group, run:
ansible web_servers -i inventory.ini -m ping
This command targets all hosts in the web_servers group and executes the ping module on each.
Assigning Variables to Hosts
In real-world scenarios, you often need to assign specific variables to individual hosts. You can declare such variables directly within your Inventory file. For example, to assign an environment variable env to web1, update inventory.ini as follows:
[web_servers]
web1 ansible_host=192.168.1.10 env=production
web2 ansible_host=192.168.1.11 env=staging
Within a Playbook, you can reference these values using {{ ansible_host }} or {{ env }}.
Conclusion
In this section, we covered how to configure basic static Inventory files, how to group hosts, and how to assign host-specific variables. These foundational concepts prepare you for writing robust Ansible Playbooks—and serve as a stepping stone toward leveraging dynamic Inventory in more advanced deployments.
In the next tutorial, we’ll explore dynamic Inventory—enhancing Ansible’s flexibility and scalability. Stay tuned for the rest of this series!
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 13. Basic Inventory Configuration in Ansible?
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