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 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 assert stat, not YML. What do we have in there? Well, this is an example of stat as well as assert. Hostname is wrong. It's fully qualified hostname and hostname should match inventory. I don't have fully qualified in inventory. So we have the stat module. Haven't seen that one before. So stat is checking the path etc host. And then we have register. So we register in SDA and we use assert, and assert has that, sda.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 assert stat.yaml is giving what? Well, it's giving this, only the message assertion has failed. Now, that is a little bit boring. So let's go…

Contents