Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

Ansible inventory is the authoritative list of VPS hosts, their groups, and the connection variables Ansible needs to reach them. For a small or deliberately managed fleet, keep a YAML inventory in Git, separate shared settings into group_vars, put host-specific connection details in host_vars, and validate every change with ansible-inventory before running a play. Move to dynamic inventory when a provider or automation system creates and removes instances frequently.

What an Ansible inventory does

The Ansible Community documentation defines inventory as the list, or group of lists, of managed hosts: “Ansible automates tasks on managed nodes or ‘hosts’ in your infrastructure by using a list or group of lists known as inventory.” An inventory therefore answers three operational questions:

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Which VPSs can Ansible manage?
  • How are those VPSs grouped for targeting?
  • Which address, user, port, and SSH key should Ansible use for each host?

Inventory is not the same as a playbook. A playbook describes desired work; inventory identifies where that work can run and supplies connection behavior. Keep the inventory in version control so additions, removals, group changes, and connection changes are reviewed as infrastructure code.

Use a repository layout that separates environments

A practical starting layout for a VPS project is:

ansible/
  inventories/
    production/
      hosts.yml
      group_vars/
        all.yml
        web.yml
        db.yml
      host_vars/
        web-01.yml
        db-01.yml
  playbooks/
    site.yml

The hosts.yml file defines hosts and group membership. Variables shared by every host or by a group live under group_vars. Exceptional values for one machine live under host_vars. A separate inventories/staging tree keeps staging values and membership independent from production.

#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter | 4Pack Type C Female to A Male Cable Converter for Apple Duo 17 16 15 14 Plus,iWatch Watch 12 11 10,iPad 9 8 Air,Airpods 5 4
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.

Ansible’s default inventory location is /etc/ansible/hosts. In a repository, select the intended file explicitly with -i, for example:

ansible-inventory -i inventories/production/hosts.yml --graph

Using an explicit path prevents a command from silently reading a different system-wide inventory.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose YAML or INI

Format Best fit Strengths Trade-offs
YAML Nested groups, structured variables, or a growing repository Hierarchical structure is visible, indentation makes parent-child relationships explicit, and complex host data is easier to review Indentation errors can invalidate the file; consistent formatting is important
INI A short list of hosts and simple groups Compact and quick to edit for a small fleet Nested relationships and structured values are less obvious as the inventory grows

Both formats are valid static inventories. Select YAML when groups and variables have enough structure that a reviewer benefits from seeing the hierarchy. Select INI when a concise host-and-group list is all you need; migrate later if the file becomes difficult to audit.

Build a static YAML inventory

1. Define hosts and connection details

Create inventories/production/hosts.yml:

all:
  children:
    web:
      hosts:
        web-01:
          ansible_host: 203.0.113.10
          ansible_user: deploy
        web-02:
          ansible_host: 203.0.113.11
          ansible_user: deploy
    db:
      hosts:
        db-01:
          ansible_host: 203.0.113.20
          ansible_user: deploy
          ansible_port: 2222

web-01, web-02, and db-01 are Ansible host names. They are stable labels used in play patterns and do not have to match DNS names. ansible_host is the address Ansible actually connects to, ansible_user is the remote account, and ansible_port overrides the normal SSH port for the database host.

Using documentation-only addresses such as 203.0.113.10 in an example is safe; replace them with the reachable addresses of your VPSs. Do not use a public address merely because it is listed by a provider if the control node must reach the machine over a private network.

2. The equivalent compact INI form

[web]
web-01 ansible_host=203.0.113.10 ansible_user=deploy
web-02 ansible_host=203.0.113.11 ansible_user=deploy

[db]
db-01 ansible_host=203.0.113.20 ansible_user=deploy ansible_port=2222

Host variables can be written inline in INI, but keeping many values on one line quickly becomes hard to review. The YAML form is usually easier once you need nested groups or several connection parameters.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Sale
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter | USB C Dongle with 90W Max Power Delivery, 3×5Gbps USB A Data Ports, for MacBook, Dell, and More (Charger Not Included)
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.

Design groups around how you operate

Start with operational roles

Group by the work a play performs: web, db, and monitoring are useful examples. A role-oriented group lets a play target exactly the machines that need a change, such as web-server configuration without touching databases.

Add orthogonal dimensions

After role groups, add independent dimensions such as production, staging, a region, or a provider. A host may belong to several groups at once. That avoids copying a host definition merely to express its environment and location.

For example, a production web host can be a member of both production and web, while also belonging to a region group. You can then target the intersection with production:&web. Quote that pattern in a shell command because the ampersand has shell meaning:

ansible-playbook -i inventories/production/hosts.yml playbooks/site.yml --limit 'production:&web'

Use a group hierarchy when it reflects a real relationship. For instance, production can contain web and database child groups. Keep environment and role concepts distinct enough that a host can be selected by either dimension.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Understand implicit groups

Ansible supplies an implicit all group containing every host. Hosts that are not members of another explicit group appear in ungrouped. These groups are useful diagnostics: an unexpected host under ungrouped often means a group declaration or indentation error.

Put variables in the right place

Group-wide values belong in group_vars

Place values shared by all hosts in group_vars/all.yml, and values shared by one role in a matching file such as group_vars/web.yml or group_vars/db.yml. A file can contain ordinary YAML variables used by your roles:

Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter | 85W Max PD, 2 USB 3.0 & 1 USBC Data Ports, SD/TF Card Reader, for Laptops/Mac and Other Type C Devices (Charger Not Included)
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
# inventories/production/group_vars/web.yml
web_service_name: nginx

# inventories/production/group_vars/db.yml
database_backup_enabled: true

The variable names above are examples for roles you write; inventory does not require those particular names. The important rule is scope: do not repeat the same group value in every host entry.

Host-specific values belong in host_vars

Use host_vars/<host-name>.yml for a one-off value or connection exception:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
# inventories/production/host_vars/db-01.yml
ansible_port: 2222
ansible_ssh_private_key_file: ~/.ssh/production-db

The file name must match the inventory host name, not necessarily its IP address. If every database uses the same nonstandard port, put ansible_port in group_vars/db.yml instead and override it only for exceptions.

Common SSH connection variables

  • ansible_host: the address or resolvable name used for the connection.
  • ansible_user: the remote account.
  • ansible_port: the SSH port when it differs from the default.
  • ansible_ssh_private_key_file: the private key Ansible should use.

These are behavioral connection parameters. Keep them close to the inventory scope that owns them, and verify that the control node can reach the address and port before diagnosing Ansible itself.

Protect secrets

Never commit passwords, private keys, or other credentials to an inventory repository. Use Ansible Vault for secret values, restrict permissions on the control node, and keep private-key files outside the repository. A connection variable that points to a key is not the key itself, but the referenced file still requires appropriate filesystem permissions.

Separate production and staging safely

Use different inventory roots when environments have different addresses, credentials, or membership:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray | Data transfer & Fast charging for MacBook, iPhone 17/16/15, iPad, Samsung Galaxy, Apple Watch
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
inventories/
  production/
    hosts.yml
    group_vars/
    host_vars/
  staging/
    hosts.yml
    group_vars/
    host_vars/

Run a playbook with the environment you intend:

ansible-playbook -i inventories/staging/hosts.yml playbooks/site.yml
ansible-playbook -i inventories/production/hosts.yml playbooks/site.yml

This explicit choice is safer than relying on a default file whose contents may change. It also makes pull-request review clearer: a production host addition appears in the production inventory, while staging changes remain isolated.

Inspect and validate before changing anything

View the parsed group tree

ansible-inventory -i inventories/production/hosts.yml --graph

The graph shows whether hosts landed in web, db, environment groups, or ungrouped. Check this after every structural edit.

Inspect one host’s resolved data

ansible-inventory -i inventories/production/hosts.yml --host web-01

Use the result to confirm the final address, user, port, key path, and variables Ansible associates with that host. This catches a misspelled host name or a variable placed under the wrong group.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Test connectivity with the ping module

ansible all -i inventories/production/hosts.yml -m ping

A successful response confirms that Ansible can select the hosts, establish the configured connection, authenticate, and execute the module. It does not prove that an application port or service is healthy; those are separate checks.

Use a narrow first run

For a playbook change, begin with one host or one role group:

ansible-playbook -i inventories/production/hosts.yml playbooks/site.yml --limit web-01
ansible-playbook -i inventories/production/hosts.yml playbooks/site.yml --limit web

Expand the limit only after the result is what you expect. The --limit option is a second safety boundary even when the play’s host pattern is broad.

Best Value
Sale
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display | 85W Max PD, 1 Powered USB-C 5Gbps & 2 Powered USB-A 3.0 5Gbps Data Ports, for MacBook Pro, MacBook Air, Dell and More (Black)
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Target VPSs precisely

Use a play’s host pattern for the normal scope and --limit for an operational restriction. Typical choices include:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • web for every host in the web group.
  • web-01 for one named host.
  • production:&web for hosts that are members of both groups.
  • all for every host in the selected inventory, which should be used deliberately.

Always specify the inventory file as well as the limit. A correct pattern against the wrong environment is still a dangerous run.

Static versus dynamic inventory

Decision axis Static inventory files Dynamic inventory source
Change frequency Best when VPS membership changes deliberately and infrequently Best when instances are created and destroyed frequently by a cloud or hosting system
Source of truth Git-managed YAML or INI A provider API or another system discovered through an inventory plugin or dynamic source
Reviewability Every host and group change can be reviewed in a commit Membership is discovered at run time; review moves to provider or automation changes
Secret handling Keep only non-secret connection metadata in the repository and protect secrets with Vault Protect plugin credentials and any returned sensitive data using the provider and Ansible’s secret-management practices
Targeting precision Explicit groups and host names are easy to inspect Depends on the plugin’s discovered groups and supported grouping options
Failure mode A malformed or stale file is visible in version control and can be validated before a run An unavailable provider or API can prevent membership discovery or return incomplete data

When to switch

Stay with a static file when the VPS list changes through controlled, reviewed operations. Choose an inventory plugin or another dynamic source when the provider is the system that creates and removes instances and manual synchronization is becoming a regular source of errors. The dynamic source should discover membership; stable role or environment groups can remain layered over it when the plugin supports that model.

Continue to run ansible-inventory --graph against the dynamic source. Discovery is not a reason to skip inspection; it is a reason to inspect the generated result immediately before a change.

Troubleshoot the failures that matter most

The host is unreachable

  • Check ansible_host for a typo or an address unreachable from the control node.
  • Check ansible_user and confirm that the account exists and is allowed to log in.
  • Check ansible_port when SSH is not using its normal port.
  • Check ansible_ssh_private_key_file, file permissions, and whether the corresponding public key is authorized on the VPS.
  • Confirm network access and firewall rules independently of Ansible.

Run ansible-inventory --host <host-name> first. If the resolved values are wrong, fix inventory scope before changing SSH or playbook code.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The play reaches the wrong machines

Inspect --graph, verify environment selection with -i, and apply a host-level --limit for the next run. A host that appears under ungrouped may have been omitted from the intended role or environment group.

An inventory file fails to parse

YAML is indentation-sensitive. Keep child mappings consistently indented, avoid tabs, and validate the parsed result with ansible-inventory before running a playbook. In INI, check group headers and keep host variables on the same line as the intended host.

A host has the wrong port or key

Look for the variable at every applicable scope: inline host data, host_vars, and group_vars. Put shared behavior at group scope and leave only genuine exceptions in host_vars; this reduces accidental overrides.

A dynamic inventory run changes unexpectedly

Check whether the provider API is reachable and whether the plugin returned the expected groups. Treat an unavailable or partially responding provider as an operational failure: do not proceed until the discovered host set is known and reviewed.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A repeatable inventory change checklist

  1. Choose the correct environment inventory path.
  2. Add or edit the host in the role and environment groups that describe its purpose.
  3. Set ansible_host, ansible_user, ansible_port, or the key path only at the narrowest necessary scope.
  4. Put shared settings in group_vars and one-off settings in host_vars.
  5. Keep passwords and private keys out of Git; use Ansible Vault for secrets.
  6. Run ansible-inventory --graph and inspect each changed host with --host.
  7. Run ansible ... -m ping against the intended inventory.
  8. Apply the playbook first with --limit to one host or a small role group.
  9. Review the resulting change and expand the target only when the scope is correct.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.