Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversHalloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
VGSources
Blog

How to Set Up Ansible Inventories for Your VPS Fleet

A practical guide to organizing Ansible inventories for a VPS fleet, with a version-controlled YAML layout, group and host variables, SSH settings, validation commands, safe targeting patterns, troubleshooting, and static-versus-dynamic design criteria.
Length11 min Posted Quest giverVGSources Team
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For a VPS fleet, keep one version-controlled inventory per environment, describe hosts in YAML, group them by the work they perform, and store shared settings in group_vars. Put connection-specific values such as ansible_host, ansible_user, and ansible_port beside each host or in host_vars. Validate the parsed inventory with ansible-inventory, test access with the ping module, and use host patterns plus --limit before making changes.

This arrangement gives you a reviewable source of truth in Git while still allowing one VPS to belong to several operational, environment, region, or provider groups. Static files are usually the clearest choice when machines are added deliberately; move to a dynamic inventory plugin when a cloud or hosting system is constantly creating and destroying instances.

As an Amazon Associate I earn from qualifying purchases.

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.

What an Ansible inventory does

Ansible’s inventory is the authoritative list of managed VPS hosts, their group membership, and variables that describe how Ansible should connect to them. The Ansible Community documentation defines inventory as “a list or group of lists” used to automate managed nodes. A playbook can only act on hosts that its selected inventory exposes, so an incorrect inventory can be as dangerous as an incorrect task.

An inventory answers four practical questions:

  • Which machines exist in this environment?
  • Which roles does each machine perform, such as web, database, monitoring, or worker?
  • How should Ansible reach each machine over SSH?
  • Which hosts should a particular play affect?

Keep the inventory separate from playbooks. Playbooks describe desired state; the inventory describes where that state belongs. Store both in the same infrastructure repository so a reviewer can see host additions, removals, group changes, and variable changes in one pull request.

#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.

A repository layout that scales from a few VPSs

A practical starting layout is:

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

The directory name is not special; the separation is. Each environment gets its own inventory file and variable directories, which prevents a staging run from accidentally using production hosts. You can add separate inventories for a test lab, a disaster-recovery region, or a temporary migration without changing the playbooks themselves.

Ansible’s default inventory location is /etc/ansible/hosts. For a repository-based workflow, select the intended file explicitly with -i, or set an inventory path in ansible.cfg. Explicit selection is safer in CI and during incident response because the command shows exactly which environment is being used.

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

YAML or INI: choose the format that matches the fleet

Both formats are supported. Use INI for a short, flat host list; use YAML when nested groups, structured variables, or multiple dimensions make the relationship between hosts easier to review.

Consideration INI YAML
Best fit A small fleet with simple host and group lists Nested groups, structured data, and long-lived repositories
Readability Compact for a few hosts Explicit hierarchy and easier extension
Variables Convenient for simple host-line values Natural mapping for dictionaries and lists
Growth path Can become difficult to audit when groups multiply Usually easier to expand without duplicating hosts
Operational rule Use one syntax consistently in a given inventory Validate indentation and key nesting before a run

There is no performance advantage that should drive this choice for an ordinary VPS fleet. Reviewability and the likelihood of a safe change matter more. The examples below use YAML because it makes parent groups and host variables visible.

Build a YAML inventory step by step

1. Create the environment directory

From the repository root, create the inventory and variable directories:

mkdir -p inventories/production/group_vars inventories/production/host_vars

Create inventories/production/hosts.yml with a top-level all group. Under children, define the operational groups that playbooks will target.

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

2. Add hosts and connection details

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

The names web-01, web-02, and db-01 are inventory aliases. They are the names used in play patterns, even when the machines’ DNS names or public addresses differ. ansible_host supplies the address Ansible actually contacts; it can be an IP address or a resolvable DNS name.

3. Add explicit environment groups when they help targeting

If the same repository contains several environments, place the role groups below an environment group:

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.
all:
  children:
    production:
      children:
        web:
          hosts:
            web-01:
              ansible_host: 203.0.113.10
              ansible_user: deploy
        db:
          hosts:
            db-01:
              ansible_host: 203.0.113.20
              ansible_user: deploy
    staging:
      children:
        web:
          hosts:
            stage-web-01:
              ansible_host: 198.51.100.30
              ansible_user: deploy

Do not duplicate a host merely to express another dimension. A host can belong to several groups. In a larger inventory, you might place a VPS in web, production, eu-west, and provider_a at the same time.

Design groups around operations, then add dimensions

Start with groups that represent what a machine does: web, db, monitoring, queue, or backup. These groups map directly to roles and playbooks. Add orthogonal groups for environment, region, provider, compliance boundary, or maintenance window.

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

This avoids a combinatorial naming scheme such as production_eu_web_provider_a. Composite names encode several facts in one string and force you to create a new group for every combination. Independent groups let Ansible calculate the intersection when needed.

Useful host patterns

  • web targets every member of the web group.
  • production targets all production hosts.
  • production:&web targets hosts that are in both groups.
  • production:!db targets production hosts except database hosts.
  • web:db targets the union of web and database hosts.
  • web-01 targets one inventory alias.
  • all targets every parsed host.

Ansible also supplies an implicit all group. Hosts that are not members of another explicit group appear in the implicit ungrouped group. Seeing unexpected hosts in ungrouped is often a sign that a group declaration or indentation is wrong.

Where to put variables

Keep values at the narrowest scope that accurately describes them. Shared defaults belong in group_vars; one-off host facts belong in host_vars. This keeps the main inventory focused on membership and connection identity.

Group variables

Create inventories/production/group_vars/all.yml for settings shared by every production host:

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.
timezone: UTC
ntp_enabled: true
admin_groups:
  - sudo
  - deploy

Create group_vars/web.yml for web-only values:

http_listen_port: 80
https_listen_port: 443
web_package_state: present

Create group_vars/db.yml for database settings. Keep secrets out of these ordinary YAML files; encrypted secret variables should be managed separately with Ansible Vault.

Host variables

Use host_vars/web-01.yml when one machine needs an exception:

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.
backup_window: '02:30'
web_memory_profile: large

Typical connection variables include:

  • ansible_host: the address to connect to.
  • ansible_user: the remote SSH account.
  • ansible_port: the SSH port when it is not the default.
  • ansible_ssh_private_key_file: a private-key path on the control node.

Use a private-key path only when the control node has that key through a protected provisioning or secret-management process. Never commit a private key or plaintext password to the repository. Restrict permissions on files containing credentials, and use Ansible Vault for encrypted secrets. Host-key checking and SSH connection behavior are controlled by Ansible’s connection settings; do not disable host-key checking broadly just to hide a trust problem.

Separate connection identity from application data

An inventory alias should remain stable even if a provider reallocates an address. Keep web-01 as the logical identity and change only ansible_host when the address changes. This preserves playbook targeting, host-specific history, and monitoring references.

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

For a fleet using one SSH account and key, define those defaults once in group_vars/all.yml or in a dedicated connection group, then override only the hosts that differ:

ansible_user: deploy
ansible_ssh_private_key_file: /secure/path/production_deploy_ed25519

If a database uses a nonstandard SSH port, keep that exception next to the database host or in its host variables:

ansible_port: 2222

Do not place a provider’s API token, database password, or application secret in hosts.yml. Inventory files are frequently displayed in diagnostics and code review, so treating them as public metadata reduces accidental disclosure.

Validate the inventory before running a playbook

Validation should be a separate, repeatable step. Run these commands from the repository root:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
ansible-inventory -i inventories/production/hosts.yml --graph
ansible-inventory -i inventories/production/hosts.yml --host web-01
ansible all -i inventories/production/hosts.yml -m ping

Read the graph

--graph shows the groups and host membership Ansible parsed. Confirm that production and staging hosts are not mixed, that every expected role group exists, and that a host has not accidentally become ungrouped. This catches YAML indentation errors and incorrect parent-child relationships before any task changes a server.

Inspect one host

--host web-01 displays the variables Ansible associates with that alias. Check the resolved address, user, port, and any host-specific values. If the output does not contain the expected connection data, fix variable placement or naming before testing SSH.

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

Test connectivity

The ping module verifies that Ansible can authenticate and execute a basic module; it does not send an ICMP ping. A successful response confirms that the selected user, key, port, Python availability, and host identity are sufficient for a basic Ansible connection. A failure message should be treated as a connection problem to resolve before running a configuration play.

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

Target narrowly and reduce blast radius

Even a correct inventory can be used unsafely if a broad play pattern is chosen. Start with the smallest meaningful target, then expand only after checking the result.

ansible-playbook -i inventories/production/hosts.yml site.yml --limit web-01
ansible-playbook -i inventories/production/hosts.yml site.yml --limit web
ansible-playbook -i inventories/production/hosts.yml site.yml --limit 'production:&web'
  1. Run ansible-inventory --graph and verify membership.
  2. Use --limit for one canary host.
  3. Review the play recap and application health.
  4. Expand to the role group only when the canary is healthy.
  5. Run the full environment last, with a change record and rollback plan.

Quote patterns containing shell metacharacters so the local shell does not interpret them. Keep the inventory path explicit in scripts and CI jobs. A command that omits -i can silently use /etc/ansible/hosts or another configured source.

Organize multiple environments safely

For separate production and staging fleets, the clearest arrangement is usually one directory per environment:

inventories/
  production/
    hosts.yml
    group_vars/
    host_vars/
  staging/
    hosts.yml
    group_vars/
    host_vars/

Use the same group names in both environments where the playbooks are intended to be reusable. For example, both inventories can define web and db, while the actual aliases, addresses, and sizing differ. This lets site.yml target web without embedding environment-specific hostnames.

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

Do not solve environment separation by relying on a developer’s current directory or an undocumented default. Put the inventory selection in the command, CI configuration, or a checked-in wrapper script. Review any pull request that adds a production host as carefully as a code change that grants access.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Static inventory versus dynamic inventory

Static files are appropriate when the VPS list changes deliberately and infrequently. A Git change records who added or removed a machine, when the change occurred, and which variables changed. This is often the best failure mode for a small fleet: if a provider API is unavailable, the last known inventory remains inspectable and can still be used.

Use an inventory plugin or another dynamic source when a cloud or hosting system creates and destroys instances frequently. The dynamic source discovers current membership from the provider rather than waiting for someone to edit a file. Keep stable role and environment groups layered over the discovered data when the plugin supports grouping or keyed metadata.

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.
Axis Static inventory Dynamic inventory
Change frequency Manual or deliberate changes Frequent automated creation and deletion
Source of truth Version-controlled Git files Provider or orchestration API
Reviewability Every membership change can be reviewed Changes may occur outside Git unless snapshots are recorded
Targeting Explicit groups and aliases you maintain Groups derived from provider metadata, where supported
Failure mode May become stale until someone edits it Discovery can fail when the provider API or credentials are unavailable
Best fit A stable VPS fleet with intentional changes Autoscaled or short-lived instances

Dynamic inventory is not automatically better. It adds provider credentials, plugin configuration, API availability, and a new debugging path. Choose it when stale membership is a bigger operational risk than an unavailable discovery service.

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

Common failures and fixes

“No hosts matched”

Check the exact spelling and case of the play’s hosts: pattern. Run ansible-inventory --graph and confirm that the group exists in the selected file. Also verify that you did not accidentally select staging with -i while targeting a production-only group.

Ansible connects to the wrong address

Inspect the host with ansible-inventory --host web-01. The inventory alias is not necessarily the network address. Correct ansible_host, remove a stale host variable, or fix variable precedence if a group value is overriding the intended host value.

Permission denied or connection refused

Verify ansible_user, the private-key path, and ansible_port. Test the same identity with an SSH command from the control node. A refused connection usually indicates an address, firewall, or port problem; a permission error usually indicates the wrong account or key. Do not work around either by disabling security checks globally.

YAML parses but groups are wrong

YAML indentation determines hierarchy. A host indented under the wrong group can be valid YAML while producing incorrect inventory membership. Compare the parsed --graph output with the intended design, then make the smallest indentation change and rerun validation.

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

Secrets appear in a diff

Remove the plaintext value, rotate the exposed credential, and move the replacement into an encrypted Vault-managed file or an approved secret store. Adding the file to .gitignore does not remove a secret already committed to history.

Version-control and operating practices

  • Require review for host additions, removals, group changes, and connection-variable changes.
  • Keep production and staging inventories in separate paths and name them explicitly in automation.
  • Use stable aliases rather than embedding temporary provider names in every playbook.
  • Run ansible-inventory --graph and a connectivity check in CI where credentials and network policy allow it.
  • Document who owns each group and how a retired VPS is removed.
  • Protect the control node and restrict permissions on SSH keys, Vault passwords, and decrypted temporary files.
  • Record dynamic-inventory plugin versions and provider credential scopes so discovery failures are diagnosable.

Inventory is infrastructure code. A pull request that changes ansible_port can alter access to an entire group; a change to group membership can redirect a destructive play. Treat those changes with the same review discipline as application deployment code.

Optional background reading

Ansible for DevOps: Server and Configuration Management for Humans by Jeff Geerling is an optional reference for readers who want a broader explanation of Ansible workflows, from a single server to large fleets. A book can clarify concepts and examples, but use the current Ansible Community documentation for command behavior, inventory plugins, connection parameters, and security guidance because digital and printed editions can age at different rates.

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.

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

Leave a Reply

Your email address will not be published. Required fields are marked *

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

More quests from Patch Notes

  1. How to Set Up a RedM (RDR2) Server in 2026: License Key, txAdmin and server.cfg, Step by StepBlog11min
  2. Best RedM (RDR2) Server Hosting in 2026: Comparing Four Hosts on Slots, Memory and PriceBlog10min
  3. How to Host a Mindustry Server in 2026: server-release.jar, Port 6567 and the Commands That MatterBlog7min
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.