-
Notifications
You must be signed in to change notification settings - Fork 23.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clarification on host targeting in playbooks #81651
Comments
Files identified in the description: If these files are incorrect, please update the |
Personally, I don't think this needs to be documented. You're not supposed to give hosts and groups the same name, so leaving that as undefined behaviour is fine. Mainly, though, I wanted to point out that |
Even though you're maybe not supposed to, there's currently nothing stopping you from doing it, and Ansible will happily execute the playbook without any kind of confirmation by the user. If this is something that's not supposed to happen Ansible should probably throw an error and prevent the execution to prevent any unwanted or accidental scenarios. As for the explanation, thanks. I wasn't aware of that. I only just started learning Ansible. |
not sure why this is not supposed to happen, Ansible is just executing what you ask it to, there is no real way to know that it does not really match your intentions. needs_info |
That was my idea too. The way I'm seeing it:
|
I believe the warning should just be extended to indicate that the group of the same name can not be targeted by limits. It still works in the sense that |
Summary
I ran into a scenario where I had to target a single host, instead of a group. Since both appeared to use the same
hosts:
syntax this got me thinking, what if both a host and group share the same name? What is the processing order?Example inventory:
Example playbook:
Using these files for a quick test shows that Ansible does output a warning, but proceeds by only selecting the host
web
.It's not until you set
hosts
to beweb:*
that it will select all hosts within the groupweb
instead (which, given the child selector, makes sense).This documentation page about targeting hosts doesn't appear to mention anything about the order in which ansible selects the matching patterns.
Although I'm sure it's not considered best-practice, nor recommended to have a host share the same name with a group, I think the documentation would still benefit from clarification on what behavior to expect from Ansible.
Given my test it would appear that Ansible prioritizes a
host
over agroup
with the same name, until a child-selector is provided. This however, is just an assumption, and would benefit from actual documentation to prevent any unexpected scenarios.Issue Type
Documentation Report
Component Name
playbook
Ansible Version
Configuration
OS / Environment
N/A
Additional Information
It would help clarify the expected behavior of Ansible in edge-cases like this.
Code of Conduct
The text was updated successfully, but these errors were encountered: