From the course: Complete Guide to Configuration Management Using Ansible
Unlock this course with a free trial
Join today to access over 25,200 courses taught by industry experts.
Using assert - Ansible Tutorial
From the course: Complete Guide to Configuration Management Using Ansible
Using assert
In this video, we'll talk about the assert module. So the assert module can be used to show a message on success as well as on failure. So it's very much like the fail module, with the difference that here, we also have a success message. Let me demonstrate. All right. Let's start with some examples. So assertstat.yml. What do we have in there? Well, this is an example of stat as well as assert. Hostname is wrong. It's a fully qualified hostname, and hostname should match inventory. I don't have fully qualified in inventory. So we have the stat module, I haven't seen that one before. So stat is checking the path /etc/hosts. And then we have register. So we register in sta, and we use assert. And assert has that sta.stat.isdir. So in the output of the stat module, you have an isdir key, and that is what we are going to check. So ansible-playbook on assertstat.yml is giving what? Well, it's giving this. Only the message section has failed. Now that is a little bit boring, so let's go…
Contents
-
-
-
-
-
-
-
-
-
(Locked)
Learning objectives43s
-
(Locked)
Conditionals overview1m 37s
-
(Locked)
Using loop to process a list of items11m 24s
-
(Locked)
Using handlers for conditional task execution7m 42s
-
(Locked)
Using when to run tasks in specific situations11m 16s
-
(Locked)
Using register to work with task results4m 9s
-
(Locked)
Using blocks5m 31s
-
(Locked)
Managing failure with the fail module5m 33s
-
(Locked)
Using assert5m 29s
-
(Locked)
Lesson 7 lab: Using when to create idempotency46s
-
(Locked)
Lesson 7 lab solution: Using when to create idempotency5m 47s
-
(Locked)
-
-
-
-
-
-