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.
[WARNING]: provided hosts list is empty, only localhost is available.
Note that the implicit localhost does not match 'all'
PLAY [web] *** skipping: no hosts matchedCommon 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
[inventory]
enable_plugins = aws_ec2, host_list, yaml, ini
# verify
ansible-inventory -i inventory.aws_ec2.yml --graphFix filters and credentials
- Loosen or correct the plugin’s
filters/regionsso they match real instances. - Provide cloud credentials and region to the runner (the same chain the provider uses).
- Run
ansible-inventory --listto see exactly what the plugin returns.
How to prevent it
- Add an
ansible-inventory --graphcheck 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.