mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-06-28 03:00:23 -07:00
Clarify include section
This commit is contained in:
parent
16c4802476
commit
0c2dd7b057
1 changed files with 12 additions and 10 deletions
|
@ -405,12 +405,7 @@ Include directives look like this::
|
||||||
- tasks:
|
- tasks:
|
||||||
- include: tasks/foo.yml
|
- include: tasks/foo.yml
|
||||||
|
|
||||||
Variables passed in can be used in the include files too. Assume a variable named 'user'. Using
|
You can also pass variables into includes directly. We might call this a 'parameterized include'.
|
||||||
`jinja2` syntax, anywhere in the included file, you can say::
|
|
||||||
|
|
||||||
{{ user }}
|
|
||||||
|
|
||||||
I can also pass variables into includes directly. We might call this a 'parameterized include'.
|
|
||||||
|
|
||||||
For instance, if deploying multiple wordpress instances, I could
|
For instance, if deploying multiple wordpress instances, I could
|
||||||
contain all of my wordpress tasks in a single wordpress.yml file, and use it like so::
|
contain all of my wordpress tasks in a single wordpress.yml file, and use it like so::
|
||||||
|
@ -420,15 +415,22 @@ contain all of my wordpress tasks in a single wordpress.yml file, and use it lik
|
||||||
- include: wordpress.yml user=alice
|
- include: wordpress.yml user=alice
|
||||||
- include: wordpress.yml user=bob
|
- include: wordpress.yml user=bob
|
||||||
|
|
||||||
|
Variables passed in can be used in the included files. Using
|
||||||
|
`jinja2` syntax, in the included file, you can reference them like this::
|
||||||
|
|
||||||
|
{{ user }}
|
||||||
|
|
||||||
|
or, more simply, using Ansible's simplified variable syntax::
|
||||||
|
|
||||||
|
$user
|
||||||
|
|
||||||
In addition to the explicitly passed in parameters, all variables from
|
In addition to the explicitly passed in parameters, all variables from
|
||||||
the vars section are also available for use here as well. Variables that bubble
|
the vars section are also available for use here as well.
|
||||||
up from tools like facter and ohai are not usable here though -- but they ARE available for use
|
|
||||||
inside 'action' lines and in templates.
|
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
Include statements are only usable from the top level
|
Include statements are only usable from the top level
|
||||||
playbook file. This means includes can not include other
|
playbook file. This means includes can not include other
|
||||||
includes.
|
includes. This may be implemented in a later release.
|
||||||
|
|
||||||
Includes can also be used in the 'handlers' section, for instance, if you
|
Includes can also be used in the 'handlers' section, for instance, if you
|
||||||
want to define how to restart apache, you only have to do that once for all
|
want to define how to restart apache, you only have to do that once for all
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue