2018-08-27 21:57:32 +02:00
.. _special_variables:
Special Variables
=================
Magic
-----
2018-11-16 00:46:41 +01:00
These variables cannot be set directly by the user; Ansible will always override them to reflect internal state.
2018-08-27 21:57:32 +02:00
ansible_check_mode
Boolean that indicates if we are in check mode or not
2018-11-15 16:01:29 +01:00
ansible_dependent_role_names
The names of the roles currently imported into the current play as dependencies of other plays
2018-08-27 21:57:32 +02:00
ansible_diff_mode
Boolean that indicates if we are in diff mode or not
ansible_forks
Integer reflecting the number of maximum forks available to this run
ansible_inventory_sources
List of sources used as inventory
2018-11-02 19:38:29 +01:00
ansible_limit
Contents of the `` --limit `` CLI option for the current execution of Ansible
2018-12-07 20:49:50 +01:00
ansible_loop
A dictionary/map containing extended loop information when enabled via `` loop_control.extended ``
2018-08-27 21:57:32 +02:00
ansible_play_batch
List of active hosts in the current play run limited by the serial, aka 'batch'. Failed/Unreachable hosts are not considered 'active'.
ansible_play_hosts
The same as ansible_play_batch
ansible_play_hosts_all
List of all the hosts that were targeted by the play
2018-11-15 16:01:29 +01:00
ansible_play_role_names
The names of the roles currently imported into the current play. This list does **not** contain the role names that are
implicitly included via dependencies.
2018-08-27 21:57:32 +02:00
ansible_playbook_python
The path to the python interpreter being used by Ansible on the controller
2018-11-15 16:01:29 +01:00
ansible_role_names
The names of the roles currently imported into the current play, or roles referenced as dependencies of the roles
imported into the current play.
2018-11-02 19:38:29 +01:00
ansible_run_tags
Contents of the `` --tags `` CLI option, which specifies which tags will be included for the current run.
2018-09-28 18:20:12 +02:00
ansible_search_path
2018-08-27 21:57:32 +02:00
Current search path for action plugins and lookups, i.e where we search for relative paths when you do `` template: src=myfile ``
2018-11-02 19:38:29 +01:00
ansible_skip_tags
Contents of the `` --skip_tags `` CLI option, which specifies which tags will be skipped for the current run.
2018-08-27 21:57:32 +02:00
ansible_verbosity
Current verbosity setting for Ansible
ansible_version
Dictionary/map that contains information about the current running version of ansible, it has the following keys: full, major, minor, revision and string.
group_names
List of groups the current host is part of
groups
A dictionary/map with all the groups in inventory and each group has the list of hosts that belong to it
hostvars
A dictionary/map with all the hosts in inventory and variables assigned to them
inventory_hostname
The inventory name for the 'current' host being iterated over in the play
inventory_hostname_short
The short version of `inventory_hostname`
inventory_dir
The directory of the inventory source in which the `inventory_hostname` was first defined
inventory_file
The file name of the inventory source in which the `inventory_hostname` was first defined
omit
2018-11-16 00:46:41 +01:00
Special variable that allows you to 'omit' an option in a task, i.e `` - user: name=bob home={{ bobs_home|default(omit) }} ``
2018-08-27 21:57:32 +02:00
play_hosts
2018-11-16 00:46:41 +01:00
Deprecated, the same as ansible_play_batch
2018-08-27 21:57:32 +02:00
2018-11-12 17:18:49 +01:00
ansible_play_name
The name of the currently executed play. Added in `` 2.8 `` .
2018-08-27 21:57:32 +02:00
playbook_dir
The path to the directory of the playbook that was passed to the `` ansible-playbook `` command line.
2018-11-16 00:46:41 +01:00
role_name
2018-11-12 17:18:49 +01:00
The name of the currently executed role
2018-08-27 21:57:32 +02:00
role_names
2018-11-15 16:01:29 +01:00
Deprecated, the same as ansible_play_role_names
2018-08-27 21:57:32 +02:00
role_path
The path to the dir of the currently running role
Facts
-----
2018-11-16 00:46:41 +01:00
These are variables that contain information pertinent to the current host (`inventory_hostname` ). They are only available if gathered first.
2018-08-27 21:57:32 +02:00
ansible_facts
Contains any facts gathered or cached for the `inventory_hostname`
2018-11-16 00:46:41 +01:00
Facts are normally gathered by the :ref: `setup <setup_module>` module automatically in a play, but any module can return facts.
2018-08-27 21:57:32 +02:00
ansible_local
2018-11-16 00:46:41 +01:00
Contains any 'local facts' gathered or cached for the `inventory_hostname` .
2018-08-27 21:57:32 +02:00
The keys available depend on the custom facts created.
2018-11-16 00:46:41 +01:00
See the :ref: `setup <setup_module>` module for more details.
2018-08-27 21:57:32 +02:00
Connection variables
---------------------
2018-11-16 00:46:41 +01:00
Connection variables are normally used to set the specifics on how to execute actions on a target. Most of them correspond to connection plugins, but not all are specific to them; other plugins like shell, terminal and become are normally involved.
Only the common ones are described as each connection/become/shell/etc plugin can define its own overrides and specific variables.
2018-08-27 21:57:32 +02:00
ansible_become_user
2018-11-16 00:46:41 +01:00
The user Ansible 'becomes' after using privilege escalation. This must be available to the 'login user'.
2018-08-27 21:57:32 +02:00
ansible_connecion
The connection plugin actually used for the task on the target host.
ansible_host
The ip/name of the target host to use instead of `inventory_hostname` .
ansible_python_interpreter
The path to the Python executable Ansible should use on the target host.
ansible_user
The user Ansible 'logs in' as.