Ansible Register Variables
Ansible registers provide us with a nice way of capturing the results of a given task and executing a set of additional automations based on the captured results. In many ways, this is similar to variable declarations, although registers are more global in nature. Ansible registers provide us with a way of storing this captured data for later and then conditionalizing future tasks based on the results of previous ones.
Simple Ansible registers
The most basic Ansible register implementations require us to only register
the output of a given operation. An example of how to define a simple register is provided next:
--- - name: A Simple Ansible Register Example hosts: all tasks: - shell: tail -n 100 /etc/motd register: motd_contents
In this example, we use the register operator to capture the last 100 lines of the system's MOTD file and store it in a global register
variable, motd_contents
. Ansible registers essentially create a new Ansible fact at runtime, which can...