From the course: Ansible: From Basics to Guru by Pearson

Unlock this course with a free trial

Join today to access over 25,200 courses taught by industry experts.

Using register

Using register

In this video, we'll talk about a register. So what is a register used for? A register is a keyword that is used to record the result of a command or task and store it in a variable. That allows you to be very flexible and to integrate the result of Linux commands, for instance, in your Ansible environment. And thus it allows you to create variables that have a dynamic value. Let me show you an example. All right, let me show you a demo. Let me create a file regvar.yml. And in this file, I'm going to do what? Well, first, a small header, demo register, hosts. Let's do it on Ansible 1. Tasks, I am going to run an arbitrary task. a command, for instance. And let's use a date as a command and a register this date. That will create a variable with the name this date. Doesn't have to be more simple for proof of concept. Now I'm going to use debug. And in debug, I'm going to print the value of the variable this date. So Ansible playbook on reg var is going to give me what? Well, it's…

Contents