mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
2nd draft
This commit is contained in:
parent
7cf16588e8
commit
b059a95714
1 changed files with 40 additions and 10 deletions
|
@ -1,11 +1,41 @@
|
||||||
relative paths get attempted first with a 'files|templates|vars' in path (if not already present) depending on action being taken, 'files' is the default. (i.e include_vars will use vars/).
|
=======================
|
||||||
paths will be searched from most specific to most general (i.e role before play).
|
Search paths in Ansible
|
||||||
|
=======================
|
||||||
|
|
||||||
|
Absolute paths are not an issue as they always have a known start, but relative paths ... well, they are relative.
|
||||||
|
|
||||||
|
Config paths
|
||||||
|
============
|
||||||
|
|
||||||
|
By default these should be relative to the config file, some are specifically relative to the 'cwd' or the playbook and should have this noted in their description. Things like ssh keys are left to use 'cwd' because it mirrors how the underlying tools would use it.
|
||||||
|
|
||||||
|
|
||||||
|
Task paths
|
||||||
|
==========
|
||||||
|
|
||||||
|
Here things start getting complicated, there are 2 different scopes to consider, task evalution (paths are all local, like in lookups) and task execution, which is normally on the remote, unless an action plugin is involved.
|
||||||
|
|
||||||
|
Some tasks that require 'local' resources use action plugins (template and copy are examples of these), in which case the path is also local.
|
||||||
|
|
||||||
|
The magic of 'local' paths
|
||||||
|
--------------------------
|
||||||
|
|
||||||
|
Lookups and action plugins both use a special 'search magic' to find things, taking the current play into account, it uses from most specific to most general the the playbook dir in which a task is contained (this includes roles and includes).
|
||||||
|
|
||||||
|
Using this magic, relative paths get attempted first with a 'files|templates|vars' appended (if not already present), depending on action being taken, 'files' is the default. (i.e include_vars will use vars/). The paths will be searched from most specific to most general (i.e role before play).
|
||||||
dependent roles WILL be traversed (i.e task is in role2, role2 is a dependency of role1, role2 will be looked at first, then role1, then play).
|
dependent roles WILL be traversed (i.e task is in role2, role2 is a dependency of role1, role2 will be looked at first, then role1, then play).
|
||||||
role search path is rolename/{files|vars|templates}/, rolename/tasks/.
|
i.e ::
|
||||||
play search path is playdir/{files|vars|templates}/, playdir/.
|
|
||||||
the current working directory (cwd) is not searched. If you see it, it just happens to coincide with one of the paths above.
|
role search path is rolename/{files|vars|templates}/, rolename/tasks/.
|
||||||
include of a task file from a role will NOT trigger role behavior, this only happens when running as a role.
|
play search path is playdir/{files|vars|templates}/, playdir/.
|
||||||
new ansible_search_path var will have the search path used, in order.
|
|
||||||
5 vs (-vvvvv) should show the detail of the search as it happens.
|
|
||||||
this does NOT affect absolute paths
|
The current working directory (cwd) is not searched. If you see it, it just happens to coincide with one of the paths above.
|
||||||
includes try the path of the included file first and fall back to the play/role that includes them.
|
If you `include` a task file from a role, it will NOT trigger role behavior, this only happens when running as a role, `include_role` will work.
|
||||||
|
A new variable `ansible_search_path` var will have the search path used, in order (but without the appended subdirs). Using 5 "v"s (`-vvvvv`) should show the detail of the search as it happens.
|
||||||
|
|
||||||
|
As for includes, they try the path of the included file first and fall back to the play/role that includes them.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
.. note: The 'cwd' might vary depending on the connection plugin and if the action is local or remote. For the remote it is normally the directory on which the login shell puts the user. For local it is either the directory you executed ansible from or in some cases the playbook directory.
|
||||||
|
|
Loading…
Reference in a new issue