mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Merge pull request #130 from jpalley/patch-1
Add/update documentation about magic variables.
This commit is contained in:
commit
1669620379
1 changed files with 14 additions and 3 deletions
|
@ -42,14 +42,25 @@ Magic Variables
|
||||||
|
|
||||||
Some variables made available to hosts don't come from definitions in a playbook, the inventory file, or discovery from the system. There are only two of these, and are used in special cases that many users won't need.
|
Some variables made available to hosts don't come from definitions in a playbook, the inventory file, or discovery from the system. There are only two of these, and are used in special cases that many users won't need.
|
||||||
|
|
||||||
`groups` is a list (array) of all the groups the current host is in. This can be used in templates using Jinja2
|
*group_names* is a list (array) of all the groups the current host is in. This can be used in templates using Jinja2
|
||||||
syntax to make template source files that vary based on the group membership (or role) of the host::
|
syntax to make template source files that vary based on the group membership (or role) of the host::
|
||||||
|
|
||||||
{% if 'webserver' in groups %}
|
{% if 'webserver' in group_names %}
|
||||||
# some part of a configuration file that only applies to webservers
|
# some part of a configuration file that only applies to webservers
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
`inventory_hostname` is the name of the hostname as configured in Ansible's inventory host file. This can
|
|
||||||
|
*groups* is a list of all the groups (and hosts) in the inventory. This can be used to enumerate all hosts within a group.
|
||||||
|
For example::
|
||||||
|
|
||||||
|
{% for host in groups['app_servers'] %}
|
||||||
|
# something that applies to all app servers.
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
|
||||||
|
Use cases include pointing a frontend proxy server to all of the app servers, setting up the correct firewall rules between servers, etc.
|
||||||
|
|
||||||
|
*inventory_hostname* is the name of the hostname as configured in Ansible's inventory host file. This can
|
||||||
be useful for when you don't want to rely on the discovered hostname `ansible_hostname` or for other mysterious
|
be useful for when you don't want to rely on the discovered hostname `ansible_hostname` or for other mysterious
|
||||||
reasons. Don't worry about it unless you think you need it.
|
reasons. Don't worry about it unless you think you need it.
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue