Skip to content

Commit

Permalink
Document No hosts matched the subscripted pattern (#2481)
Browse files Browse the repository at this point in the history
Fixes: #2422
  • Loading branch information
ssbarnea committed Sep 21, 2022
1 parent 455a909 commit e00891b
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/ansiblelint/_internal/internal_error.md
Expand Up @@ -31,3 +31,13 @@ them to the `exclude_paths`.
hosts: localhost
tasks: []
```

## ERROR! No hosts matched the subscripted pattern

If you see this error, it means that you tried to index a host group variable
that is using an index above its size.

Instead of doing something like `hosts: all[1]` which assumes that you have
at least two hosts in your current inventory, you better write something like
`hosts: "{{ all[1] | default([]) }}`, which is safe and do not produce runtime
errors. Use safe fallbacks to make your code more resilient.

0 comments on commit e00891b

Please sign in to comment.