There three types of variables
- variables gathered from the facts which can be extracted using the following command:
ansible -m setup hostname
- pre-defined variables, you can use this playbook for it
---
# vars.yml
# Shows the value of all variables/facts.
# Example:
# ansible-playbook vars.yml -e 'hosts=localhost'
- hosts: localhost
tasks:
- fail: "You must specify a value for `hosts` variable - e.g.: ansible-playbook vars.yml -e 'hosts=localhost'"
when: hosts is not defined
- hosts: "{{ hosts }}"
tasks:
- debug: var=vars
- debug: var=hostvars[inventory_hostname]
- Variables passed through command lines which will obviously be known to you.