You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ansible/docs/docsite/rst/user_guide/playbook_pathing.rst

44 lines
2.6 KiB
ReStructuredText

[WIP] Backport/2.7/batch port (#45859) Batch of docs backports: * docs: Clarify include_task v import_tasks with conditionals (#43856) (cherry picked from commit 6be42a2a0ec6afb1e8a2f5f48bef4e9c1588dd34) * Add single quotes around package name (#45152) (cherry picked from commit 0d81386144298af42810fbf4d88668c67425d29c) * prefer ansible_facts namespace and dict notation (#44980) (cherry picked from commit 44510448b07c16bbf7767076e2392f47dcb7e824) * fix cherrypick conflict - scenario_guides * Update implicit_localhost.rst (#45455) (cherry picked from commit f68cd1acc65fe7914f4adda7eb3b6f2b1a78ef1e) * updated fbsd install instructions (#45309) (cherry picked from commit e9c2695ce745cf42d1c69166d838ad17555d8b99) * Change "Defaulting Undefined Variables" (#41379) (cherry picked from commit e35c4be1c1a5e40d1b5e2b33ac04e83e4a5fc4e7) * adds license details to dev guide pages (#45574) (cherry picked from commit 6e68d77f6dde19f5eb5c77e5f0829958597c2333) * FAQ: fix a typo, add link to 'vars' lookup (#42412) (cherry picked from commit 95649dc793e178b9b9d796865db0a1ce2c2c2355) * Fix link and toctree (#45595) (cherry picked from commit 6999bf318f7c786abdabdfa9c129a5151172cd61) * Improve the local toctree (and title) (#45590) (cherry picked from commit afea00fa9fe3e5a04b17e4016e61b9399d4a1a50) * Add undocumented configuration parameter and explain in porting guide (#36059) (cherry picked from commit a892a6ef03a0b4e0e6fc7b66c20f82154cad8a8d) * Simplify PPA installation for Ubuntu (#45690) (cherry picked from commit 78e9f452a5bb9d2c8b1d1ae9bdaa3bd86e1b972b) * adding git+ssh uri scheme (#36025) (cherry picked from commit 84a42577740b14d77e9571dfd242261b91283d94) * Add workaround for non-standard kerberos environments (#41465) (cherry picked from commit 4e532e0ad99396cbfc5dd32a0b02efcc57523b99) * Restore license agreement (#45809) (cherry picked from commit f430f60541899792356efd3ba7f31f7324731f10) * partial cherry-pick - lenovo doc update PR 45483
6 years ago
:orphan:
***********************
8 years ago
Search paths in Ansible
[WIP] Backport/2.7/batch port (#45859) Batch of docs backports: * docs: Clarify include_task v import_tasks with conditionals (#43856) (cherry picked from commit 6be42a2a0ec6afb1e8a2f5f48bef4e9c1588dd34) * Add single quotes around package name (#45152) (cherry picked from commit 0d81386144298af42810fbf4d88668c67425d29c) * prefer ansible_facts namespace and dict notation (#44980) (cherry picked from commit 44510448b07c16bbf7767076e2392f47dcb7e824) * fix cherrypick conflict - scenario_guides * Update implicit_localhost.rst (#45455) (cherry picked from commit f68cd1acc65fe7914f4adda7eb3b6f2b1a78ef1e) * updated fbsd install instructions (#45309) (cherry picked from commit e9c2695ce745cf42d1c69166d838ad17555d8b99) * Change "Defaulting Undefined Variables" (#41379) (cherry picked from commit e35c4be1c1a5e40d1b5e2b33ac04e83e4a5fc4e7) * adds license details to dev guide pages (#45574) (cherry picked from commit 6e68d77f6dde19f5eb5c77e5f0829958597c2333) * FAQ: fix a typo, add link to 'vars' lookup (#42412) (cherry picked from commit 95649dc793e178b9b9d796865db0a1ce2c2c2355) * Fix link and toctree (#45595) (cherry picked from commit 6999bf318f7c786abdabdfa9c129a5151172cd61) * Improve the local toctree (and title) (#45590) (cherry picked from commit afea00fa9fe3e5a04b17e4016e61b9399d4a1a50) * Add undocumented configuration parameter and explain in porting guide (#36059) (cherry picked from commit a892a6ef03a0b4e0e6fc7b66c20f82154cad8a8d) * Simplify PPA installation for Ubuntu (#45690) (cherry picked from commit 78e9f452a5bb9d2c8b1d1ae9bdaa3bd86e1b972b) * adding git+ssh uri scheme (#36025) (cherry picked from commit 84a42577740b14d77e9571dfd242261b91283d94) * Add workaround for non-standard kerberos environments (#41465) (cherry picked from commit 4e532e0ad99396cbfc5dd32a0b02efcc57523b99) * Restore license agreement (#45809) (cherry picked from commit f430f60541899792356efd3ba7f31f7324731f10) * partial cherry-pick - lenovo doc update PR 45483
6 years ago
***********************
8 years ago
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 playbook dir in which a task is contained (this includes roles and includes).
8 years ago
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).
8 years ago
i.e ::
role search path is rolename/{files|vars|templates}/, rolename/tasks/.
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.
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.
[WIP] Backport/2.7/batch port (#45859) Batch of docs backports: * docs: Clarify include_task v import_tasks with conditionals (#43856) (cherry picked from commit 6be42a2a0ec6afb1e8a2f5f48bef4e9c1588dd34) * Add single quotes around package name (#45152) (cherry picked from commit 0d81386144298af42810fbf4d88668c67425d29c) * prefer ansible_facts namespace and dict notation (#44980) (cherry picked from commit 44510448b07c16bbf7767076e2392f47dcb7e824) * fix cherrypick conflict - scenario_guides * Update implicit_localhost.rst (#45455) (cherry picked from commit f68cd1acc65fe7914f4adda7eb3b6f2b1a78ef1e) * updated fbsd install instructions (#45309) (cherry picked from commit e9c2695ce745cf42d1c69166d838ad17555d8b99) * Change "Defaulting Undefined Variables" (#41379) (cherry picked from commit e35c4be1c1a5e40d1b5e2b33ac04e83e4a5fc4e7) * adds license details to dev guide pages (#45574) (cherry picked from commit 6e68d77f6dde19f5eb5c77e5f0829958597c2333) * FAQ: fix a typo, add link to 'vars' lookup (#42412) (cherry picked from commit 95649dc793e178b9b9d796865db0a1ce2c2c2355) * Fix link and toctree (#45595) (cherry picked from commit 6999bf318f7c786abdabdfa9c129a5151172cd61) * Improve the local toctree (and title) (#45590) (cherry picked from commit afea00fa9fe3e5a04b17e4016e61b9399d4a1a50) * Add undocumented configuration parameter and explain in porting guide (#36059) (cherry picked from commit a892a6ef03a0b4e0e6fc7b66c20f82154cad8a8d) * Simplify PPA installation for Ubuntu (#45690) (cherry picked from commit 78e9f452a5bb9d2c8b1d1ae9bdaa3bd86e1b972b) * adding git+ssh uri scheme (#36025) (cherry picked from commit 84a42577740b14d77e9571dfd242261b91283d94) * Add workaround for non-standard kerberos environments (#41465) (cherry picked from commit 4e532e0ad99396cbfc5dd32a0b02efcc57523b99) * Restore license agreement (#45809) (cherry picked from commit f430f60541899792356efd3ba7f31f7324731f10) * partial cherry-pick - lenovo doc update PR 45483
6 years ago
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.
8 years ago
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.