ansible/ansible · error · AnsibleError
No hosts matched the subscripted pattern '%s'
Error message
No hosts matched the subscripted pattern '%s'
What it means
Error "No hosts matched the subscripted pattern '%s'" thrown in ansible/ansible.
Source
Thrown at lib/ansible/inventory/manager.py:516
If the pattern matches one or more group names according to these rules,
it may have an optional range suffix to select a subset of the results.
This is allowed only if the pattern is not a regex, i.e. '~foo[1]' does
not work (the [1] is interpreted as part of the regex), but 'foo*[1]'
would work if 'foo*' matched the name of one or more groups.
Duplicate matches are always eliminated from the results.
"""
if pattern[0] in ("&", "!"):
pattern = pattern[1:]
if pattern not in self._pattern_cache:
(expr, slice) = self._split_subscript(pattern)
hosts = self._enumerate_matches(expr)
try:
hosts = self._apply_subscript(hosts, slice)
except IndexError:
raise AnsibleError("No hosts matched the subscripted pattern '%s'" % pattern)
self._pattern_cache[pattern] = hosts
return self._pattern_cache[pattern]
def _split_subscript(self, pattern):
"""
Takes a pattern, checks if it has a subscript, and returns the pattern
without the subscript and a (start,end) tuple representing the given
subscript (or None if there is no subscript).
Validates that the subscript is in the right syntax, but doesn't make
sure the actual indices make sense in context.
"""
# Do not parse regexes for enumeration info
if pattern[0] == '~':
return (pattern, None)
View on GitHub (pinned to 9cf16a4aca)
Solutions
- Check the pattern's subscript/slice indices against the number of matched hosts.
- Verify the pattern matches the intended hosts with 'ansible-inventory --list'.
When it happens
Trigger: Thrown at lib/ansible/inventory/manager.py:516 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of ansible/ansible@9cf16a4aca (2026-08-15).
Data as JSON: /api/errors/5f0e1c5d8df8024d.
Report an issue: GitHub.