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.

The test plugin

The test plugin

The last type of plugin that we are discussing in this lesson is a test plugin. So if you feel that the when keyword doesn't give enough options, you should explore the test plugin. This plugin allows to test input on many properties. Use Ansible doc-t test-l for a list. Let's check out an example. So Ansible doc-t test-l showing all the different test plugins. Oh, my goodness, that is a lot. So here, if the file exists or if the path resolves to an existing directory, or if the path resolves to a mount point and so on, really, there are many tests available. And if you want to test something in a more advanced way, then really, you should check it out. These test plugins are kind of amazing. I have an example file, testip.yaml, which looks like this. To make it a little bit easier, this example file is not listing discovered facts, but it has a variable, all addresses, which has a list of dictionaries with IP addresses and the type. And then we have setFact that defines a new…

Contents