>Dynamic Inventories

Documentation

Dynamic inventories

Discover Ansible hosts from a repository or cloud source, check each sync, choose refresh and merge behaviour, and run ad hoc commands.

Refresh hosts from a cloud provider or a repository inventory file, check what was found, then use those stored hosts in an Ansible job. Choose how the inventory should refresh before later launches.

Before you start

You need access to the inventory and permission to manage it: inventory write for a project-scoped inventory, or organization Ansible management for an organization-scoped one. Creating a new inventory also requires organization Ansible management. Reading sync history requires organization Ansible read permission. A visible button alone does not establish that your account can perform the operation.

The sync must reach the repository and cloud APIs and have the required Ansible inventory plugin and authentication available where it runs. A VCS inventory syncs on the organization's hosted capacity unless its identity binding belongs to an agent pool, which then runs the sync if it lets the inventory's project use it; see Where a VCS inventory's file sync runs. A cloud source syncs on its project's or organization's default agent pool when one is set, and on the hosted capacity otherwise. Choose a credential or identity with read access to the resources you intend to discover.

For the cloud examples below, scope that access to the resources you need:

ProviderDiscovery access
AWSec2:DescribeInstances; region enumeration can also require ec2:DescribeRegions.
AzureThe Reader role on the target subscription or resource groups.
GCPcompute.instances.list on each target project.

Choose where configuration lives

VCS versus cloud source chooses where discovery settings live. UI, API and Terraform choose how you register and manage that definition; they are not competing inventory types. Use the UI steps below, API requests, or Terraform/OpenTofu definitions. All three paths still need a successful discovery and a host-set check.

UseWhen to choose itWhere discovery settings live
VCS inventoryReview plugin configuration in Git, including provider filters, hostnames and grouping.A plugin YAML file in the selected repository and branch.
Dynamic inventory with cloud sourcesCombine sources with their own credentials and refresh settings.Each source's configuration. Use the API for provider-specific settings the form does not expose.

The cloud-source form does not expose regions, GCP projects, Azure subscription/resource groups or a general plugin configuration editor. Its generic hostname and grouping controls are not used by the current cloud configuration generators. Configure those settings through VCS YAML or the source API config before relying on them.

Custom Script appears in the source selector but its sync implementation is incomplete. Use a supported cloud source or a VCS inventory file.

Understand the refresh

Diagram definition
flowchart LR
    A["Start sync"] --> B["Read file or source config"]
    B --> C["Discover hosts and groups"]
    C --> D["Store successful result"]
    D --> E["Check Hosts and Syncs"]
    E --> F["Launch job with stored hosts"]
What each step does

The sync reads the repository file or generates a plugin file from the cloud source configuration. It runs Ansible's inventory discovery and records the result. Jobs use the stored hosts and variables. Refreshing them is a separate operation, which can also run automatically before a job when update on launch is enabled.

Check a sync before using its hosts

  1. Wait for Synced, or read the failed source's error on Sources. A green state with zero hosts is not proof that authentication and scope are correct.
  2. Open Hosts and check the count, names, ansible_host and variables against the intended machines. Open Groups if your playbook targets generated groups.
  3. Open Syncs and select the run. Check its trigger, counts, duration and captured output. Every sync, VCS file syncs included, streams its output while it runs.
  4. Select the inventory in your job template only after the host set is appropriate.
Sync output dialog with the source, discovered hosts and successful result.

The page refreshes active sync status automatically. A local completion notification can stop waiting after about a minute; that does not cancel the sync. Return to Syncs for the final result. Warnings can accompany a successful discovery; read them before assuming the returned host set is complete.

Choose refresh and merge settings

These settings belong to individual cloud sources. A VCS inventory does not gain automatic Git refresh from this table: use Sync from VCS, then check its result before launching jobs that need repository changes. Constructed inventories have their own rebuild and cache behavior, described below.

The inventory file is authoritative. Each successful VCS sync removes the hosts and groups the file no longer lists, so a deleted VM stops being targeted and a host leaves a keyed group that disappeared. This applies to hosts and groups added by hand as well: keep every host in the file. Hosts and groups a cloud source owns are left to that source's Overwrite setting.

SettingEffect
Update on launchEnabled sources refresh before jobs use this inventory. A recent successful sync within the cache timeout can skip that refresh. The default is on.
Cache timeoutSeconds for which a successful source sync is considered fresh. Set it to 0 to refresh on every launch.
OverwriteAfter a successful sync, remove hosts/groups owned by this source that disappeared from its result. A successful empty result can remove all of that source's rows. Failed discovery leaves them unchanged.
Overwrite variablesReplace a host's variables, including manually added keys. With it off, merge variables; synced values win on conflicting keys.
Sync verbosityIncrease diagnostic output when investigating a problem, then check Syncs.

Avoid overlapping host/group names when sources must remain independent. Discovery can update an existing name and adopt a previously unowned row; a manually created name is not guaranteed protection from later overwrite pruning.

When an update-on-launch sync fails

The warning names each affected source, the failure and last successful refresh, or says that it has never synced and contributed no hosts. It appears above the job's tabs and at the start of its output, wherever the job runs. A source whose sync could not be started at all is named too; its own status stays as it was, so the job's warning is where that shows.

Refresh warnings in the API and notifications

The job API exposes inventory-sync-warnings, including each source's ID/name, failure, and last-successful-sync-at (null when there is none). Notifications sent by the template carry the warning in warnings and extra.inventory_sync_warnings. A channel subscribed only to failures will not receive a successful job's warning. Check the job or sync history when you need to establish which inventory was used.

Run an ad hoc command

  1. Select Run Command on the inventory, or the terminal action for one host.
  2. Choose a permitted module and arguments, the host limit, a machine credential and where it runs: the hosted capacity or one of your self-hosted agent pools. command and shell accept free-form arguments; other modules use key/value pairs.
  3. Run it and check the normal job page for output, events and results.

This requires ad hoc command permission, which is separate from template execution. The organization controls the module allowlist. Ad hoc jobs do not install repository Galaxy requirements. Verify the target limit before running a command that changes machines.

Delete an inventory

Choose Delete and read the dependency message before confirming. An ordinary delete can be blocked by templates, jobs, sources or constructed inputs that reference it.

To delete through the API, use:

DELETE /api/v2/ansible/inventories/<inventory-id>

For the destructive cascade, add ?force=true to that endpoint. An ordinary delete returns 409 Conflict while dependencies block it. The API force request acts immediately; it does not show the UI confirmation.