Skip to content
Latchkey

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.

ansible
ERROR! Specified hosts and/or --limit does not match any hosts

Common 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

  1. List inventory hosts with ansible-inventory --list.
  2. Ensure the --limit value is within the play hosts: set.
  3. Re-run with a limit that overlaps the play.
Terminal
ansible-playbook -i inventory site.yml --limit web1

Debug an empty dynamic inventory

Confirm the inventory plugin actually returns hosts before applying a limit.

Terminal
ansible-inventory -i aws_ec2.yml --graph

How to prevent it

  • Keep --limit values within the play host pattern.
  • Validate dynamic inventory output before deploy steps.
  • Echo the resolved limit so CI logs show what was targeted.

Frequently asked questions

What causes ""does not match any hosts""?
The --limit value names hosts outside the play pattern, so the intersection is empty.
How do I fix "does not match any hosts"?
Reconcile the play pattern and the limit

Related guides

References

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