Ansible "Specified hosts and/or --limit does not match any hosts" in CI
Ansible intersected the play pattern with --limit and the result was empty, so it stopped with an error rather than running against no hosts. The limit usually excludes everything the play would otherwise target.
What this error means
The run fails immediately with "ERROR! Specified hosts and/or --limit does not match any hosts", without executing any task.
ERROR! Specified hosts and/or --limit does not match any hostsCommon causes
A --limit that excludes the play hosts
The --limit value names hosts outside the play pattern, so the intersection is empty.
A dynamic inventory that returned no hosts
A cloud inventory plugin returned an empty result (bad filter or credentials), so there is nothing to limit against.
How to fix it
Reconcile the play pattern and the limit
- List inventory hosts with
ansible-inventory --list. - Ensure the
--limitvalue is within the playhosts:set. - Re-run with a limit that overlaps the play.
ansible-playbook -i inventory site.yml --limit web1Debug an empty dynamic inventory
Confirm the inventory plugin actually returns hosts before applying a limit.
ansible-inventory -i aws_ec2.yml --graphHow to prevent it
- Keep
--limitvalues within the play host pattern. - Validate dynamic inventory output before deploy steps.
- Echo the resolved limit so CI logs show what was targeted.