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

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