Ansible: Could Not Match Supplied Host Pattern
Red Hat Ansible
I’ve come across this Ansible
error recently. It made no sense because I had a fully populated hosts file with multiple hosts and groups.
Specifically, I was running an existing playbook and limiting its execution to just srv1:
Ansible kept giving me these errors, which seemed like an issue with (new) server srv1
I was trying to configure:
I eventually tried the same command without limit
option, and got the same error, but this time for the Ansible
server group [online]
.
Turns out, I didn’t initialise my Ansible environment correctly: ansible.cfg didn’t specify hosts file location, because of this the hostname was expected in its default location instead of my ansible homedir.
The fix for this was to implicitly define Ansible hosts location in ansible.cfg
file, under the [defaults]
section:
This fixed the issue and taught me a lesson: “could not match supplied host pattern” isn’t about pattern at all, it’s most likely about you not pointing Ansible to the correct hosts file that defines your groups and servers.
Hope this helps, have fun!
See Also
- Ansible Software
- Ansible Reference
- Getting started with Ansible
- Ansible module for Docker
- Run Ansible tasks for specific OS release version
- Create backup files when deploying with Ansible
Red Hat Ansible
I’ve come across this Ansible
error recently. It made no sense because I had a fully populated hosts file with multiple hosts and groups.
Specifically, I was running an existing playbook and limiting its execution to just srv1:
Ansible kept giving me these errors, which seemed like an issue with (new) server srv1
I was trying to configure:
I eventually tried the same command without limit
option, and got the same error, but this time for the Ansible
server group [online]
.
Turns out, I didn’t initialise my Ansible environment correctly: ansible.cfg didn’t specify hosts file location, because of this the hostname was expected in its default location instead of my ansible homedir.
The fix for this was to implicitly define Ansible hosts location in ansible.cfg
file, under the [defaults]
section:
This fixed the issue and taught me a lesson: “could not match supplied host pattern” isn’t about pattern at all, it’s most likely about you not pointing Ansible to the correct hosts file that defines your groups and servers.
Hope this helps, have fun!
See Also
- Ansible Software
- Ansible Reference
- Getting started with Ansible
- Ansible module for Docker
- Run Ansible tasks for specific OS release version
- Create backup files when deploying with Ansible