Skip to content
Latchkey

Ansible "provided hosts list is empty" - Fix Inventory Plugin in CI

Ansible loaded an inventory but found no hosts to target. A dynamic inventory plugin (aws_ec2, gcp_compute) returned nothing - disabled, mis-filtered, or unable to authenticate - so the play matches zero hosts.

What this error means

The run warns provided hosts list is empty, only localhost is available and the play skips with 0 hosts. With a dynamic plugin it is deterministic given the same config/credentials - nothing matches until the plugin is fixed.

ansible output
[WARNING]: provided hosts list is empty, only localhost is available.
Note that the implicit localhost does not match 'all'
PLAY [web] ***  skipping: no hosts matched

Common causes

Inventory plugin disabled or misconfigured

The plugin is not enabled in ansible.cfg, the inventory file does not end in a recognized suffix (e.g. *.aws_ec2.yml), or its filters match no instances.

Missing cloud credentials for the plugin

A dynamic plugin queries the cloud API; without valid credentials/region it returns an empty set rather than an obvious auth error, so the host list is empty.

How to fix it

Enable the plugin and verify it returns hosts

Enable the inventory plugin and list the computed inventory to confirm hosts appear before running the play.

ansible.cfg / Terminal
# ansible.cfg
[inventory]
enable_plugins = aws_ec2, host_list, yaml, ini

# verify
ansible-inventory -i inventory.aws_ec2.yml --graph

Fix filters and credentials

  1. Loosen or correct the plugin’s filters/regions so they match real instances.
  2. Provide cloud credentials and region to the runner (the same chain the provider uses).
  3. Run ansible-inventory --list to see exactly what the plugin returns.

How to prevent it

  • Add an ansible-inventory --graph check in CI to catch an empty inventory early.
  • Enable required inventory plugins explicitly in ansible.cfg.
  • Ensure the dynamic plugin’s cloud credentials are wired into the job.

Frequently asked questions

What causes ""hosts list is empty""?
The plugin is not enabled in ansible.cfg, the inventory file does not end in a recognized suffix (e.g. *.aws_ec2.yml), or its filters match no instances.
How do I fix "hosts list is empty"?
Enable the inventory plugin and list the computed inventory to confirm hosts appear before running the play.

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card