You can get a bunch of information about systems by gathering_facts. Then you can use any of those variables in a playbook like:
{{ ansible_devices.sda.model }}
or
{{ ansible_nodename }}
Variables
YAML syntax requires that if you start a value with {{ foo }} you quote the whole line, since it wants to be sure you aren’t trying to start a YAML dictionary.
Another major use of variables is running a command and using the result of that command to save the result into a variable. Results will vary from module to module.
How to save results of previous command
---
- hosts: all
gather_facts: no
tasks:
- name: do shell math
shell: cat /etc/passwd | wc -l
register: foovar
ignore_errors: True
- debug:
msg: "The foo var is {{ foovar.stdout_lines }} "
Registered variables
As in the aforementioned slide. Those registered variables are then available for the remainder of the playbook run (on that host).
Other reserved variables
---
- hosts: all
gather_facts: no
tasks:
- debug:
msg: "The hostvars are {{ hostvars }}"
- debug:
msg: "The group_names are {{ group_names }}"
- debug:
msg: "The groups are {{ groups }}"
Pass variables at command line
---
- hosts: all
gather_facts: no
tasks:
- debug:
msg: "The command line vars are {{ fooman }}"