vars In Ansible, basically, variables are placed in the vars section as follows.
vars
vars:
Name: tanaka
age: 25
city: tokyo
register
By using the register clause when starting the module, the value of the result based on the result of the task can be saved in the variable.
Also, if the variable contains a dictionary, {{result.hogehoge}}
or
It can be referred to as {{result ['hogegoge']}}
.
register
- name test
command: --------
register: result
debug If you want to display variables, use debug module.
debug
- debug: msg="result:{{result.hogehoge}}"
When Ansible executes a playbook, a process called GATHERING FACTS
is performed before executing the first task.
This refers to the information that Ansible has stored in variables with details about the host such as CPU architecture, OS and IP address.
These can be used like any other function.
The Official Documentation (http://bit.ly/1G9pVfx) has a partial list of available facts.
Ansible defines the following variables for use in playbooks at any time.
hostvars A dictionary that uses the Ansible host name as the key and the variable name and value mapping as the value.
inventory_hostname The name of the current host that Ansible knows
group_names List of all groups of which the current host is a member
groups A dictionary whose key is the Ansible group name and whose value is a list of host names of the members of that group.
play_hosts The host name and host of the inventory that is active in the current play.
** References **
First Ansible (written by Lorin Hochstein, translated by Ryuji Tamagawa, O'Reilly Japan Co., Ltd.)
Recommended Posts