Ansible: Could Not Match Supplied Host Pattern

Red Hat 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-playbook online.yaml --limit=srv1 --tags=techstack

Ansible kept giving me these errors, which seemed like an issue with (new) server srv1 I was trying to configure:

Could not match supplied host pattern, ignoring: srv1

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:

inventory=/Users/greys/proj/ansible/hosts

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




Keep Learning

Follow me on Facebook, Twitter or Telegram:
Recommended
I learn with Educative: Educative
IT Consultancy
I'm a principal consultant with Tech Stack Solutions. I help with cloud architectrure, AWS deployments and automated management of Unix/Linux infrastructure. Get in touch!

Recent Tweets