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.

Lesson 8 lab solution: Using when to create idempotency

Lesson 8 lab solution: Using when to create idempotency - Ansible Tutorial

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

Lesson 8 lab solution: Using when to create idempotency

So, let's create a lab7.yml, idempotent, command, hosts, ansible1 is good enough, and tasks. So what is the task? Well, we are going to use a command, useraddjohn. Next we are going to do what? We are going to use register edit user. And then we need to check what is going on. And I'm doing that by using debug and in debug the variable edit user. Because we need to figure out what is going on in this variable. And in order to figure that out, well, we need to see what exactly it looks like. So Ansible playbook on lab7.yaml. And what do we see? we see that we have a field and we have a return code, and maybe it's a return code that we should be looking at. Now, the idempotent behavior shows if we are going to run it again, because user Joan already exists. And what do we get? We get standard out already exists. So what are we going to do? Well, we are going to use the assert module. And in the assert module, We want to have an assertion and we want to have a success message and we want…

Contents