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 to work with task results

Using register to work with task results - Ansible Tutorial

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

Using register to work with task results

We have already talked about register before, I want to talk about register again because register is so powerful in combination with when statements. So you already know that the register keyword is used to store the results of a command or a task. And when can be used to run a task only if a specific result was found. And that means that you can do stuff like this. So what do we have here? Well, we have user, which is working on username, a variable obtained elsewhere. So that creates a user and puts the result in a variable with the name user. Register user creates a variable with the name user. And then a register is showing the results using debug. That might not be the most impressive example. So let's have a look at some of the code files that I prepared. So what is in register.yaml? Well, in register we have basically the example that we've just seen on the slide. So a variable username and we have user, username will be created and we have register colon user and show…

Contents