-
Notifications
You must be signed in to change notification settings - Fork 520
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
Rewrite precedence rules for more clarify #2112
base: devel
Are you sure you want to change the base?
Conversation
Thanks for your Ansible docs contribution! We talk about Ansible documentation on Matrix at #docs:ansible.im if you ever want to join us and chat about the docs! We meet on Matrix every Tuesday. See the Ansible calendar for meeting details. We welcome additions to our weekly agenda items too. You can add the |
b76fee7
to
33e912e
Compare
The changes looks to me. I would argue the problem with the precedence isn't the documentation but the fact it is very complex and convoluted. But this is out of scope. Maybe the "... adjacent to..." could be defined outside the list to keep the list clean and avoid repetition. |
@SteveRodrigue, I may be slightly odd, but every time I read group_vars/all, I can't understand what it means, there is an ambiguity between file path and logical path in the inventory. I understand that I bring a lot of verbosity, but I want to make it absolutely non-ambiguous, because of my personal bad experience when I tried to internalize those rules. You read the line, and it describes what it is beyond any doubts. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
made a few suggestions to wording and added backticks for formatting. I know some of the wording was in there before the suggested changes but might as well try and improve that while we're in here.
Thanks for the contribution @amarao
@@ -446,6 +447,8 @@ Ansible does apply variable precedence, and you might have a use for it. Here is | |||
#. include params | |||
#. extra vars (for example, ``-e "user=my_user"``)(always win precedence) | |||
|
|||
If inventory file is located in the same directory as a playbook, adjacent group_vars/ are interpreted twice both as inventory group_vars/ and playbook group_vars/, therefore, getting precedence of the playbook group_vars. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If inventory file is located in the same directory as a playbook, adjacent group_vars/ are interpreted twice both as inventory group_vars/ and playbook group_vars/, therefore, getting precedence of the playbook group_vars. | |
If an inventory file is located in the same directory as a playbook, adjacent ``group_vars/`` are interpreted twice, both as inventory ``group_vars/`` and playbook ``group_vars/``. As a result, the ``group_vars/`` from the inventory file get precedence over the playbook ``group_vars``. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is incorrect, at no point does the inventory file get precedence over the playbook's group_vars.
What happens is that since the file is processed x2, it ends up with the highest precedence, that of the playbook relative file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello, thank you for suggestion I accept it, but correct for playbook been 'stronger'.
#. host facts / cached set_facts [4]_ | ||
#. play vars | ||
#. play vars (defined in the section vars for the play) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#. play vars (defined in the section vars for the play) | |
#. play vars (defined in the ``vars`` section for the play) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there are also vars_prompt and vars_files
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was added by Don Naro
The text shows precedence by source, there is a separate text for 'group' precedence rules https://docs.ansible.com/ansible/latest/inventory_guide/intro_inventory.html#how-variables-are-merged. A change is needed, but mostly should be about vars plugins vs 'host_vars/group_vars' which are specific to the default vars plugin (host_group_vars) which is shipped with core. |
Co-authored-by: Don Naro <[email protected]>
I understand about rewriting, but within this change, should I change something? @bcoca? |
I would remove mentions of 'all' and either change the group_vars/host_vars to instances of vars plugin per group/host or make note that this is the case but using host_group_vars as an example |
I found existing explanation of precedence rules a bit confusing and not giving enough information.
This is true and it wasn't reflected in the documentation.
Proof: For an inventory
inv.yaml
:Result is:
group_vars/all
is ambiguous and can be interpreted as group_vars.all within file, also). It also allow to understand better difference between playbook and inventory group vars.group_vars/
twice, this happens when an inventory and a playbook are in the same directory, and there isgroup_vars/
directory there.There is also change for example yaml, removing trailing white spaces, done by my editor, but I think, it's correct: