Ansible - Resolve "Skipping unexpected key"

by
Jeremy Canfield |
Updated: January 30 2025
| Ansible articles
Let's say something like this is being returned.
~]$ ansible-playbook example.yml --inventory inventory.yml
[WARNING]: Skipping unexpected key (foo) in group (groups), only "vars", "children" and "hosts" are valid
[WARNING]: Skipping unexpected key (bar) in group (groups), only "vars", "children" and "hosts" are valid
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'
I got this when running the ansible-playbook command with the following inventory.yaml file.
---
hosts:
server1.example.com:
groups:
- foo
server2.example.com:
groups:
- bar
I resolved this by using the typical format for inventory YAML.
---
foo:
hosts:
server1.example.com:
bar:
hosts:
server2.example.com:
Did you find this article helpful?
If so, consider buying me a coffee over at