How can I print a warning message from within a custom module in Ansible?

413 Views Asked by At

I've created a custom module based on the description in the Ansible docs.

The docs explain to fail the module with module.fail_json(). Instead of failing and printing an error message, I want to output just a warning message without failing. How can I do that?

1

There are 1 best solutions below

0
Wolfson On BEST ANSWER

There is the warn() method to do that. For example

module.warn(f"test warning printing the module argument {module.params['name']}")

which prints out:

[WARNING]: test warning printing the module argument myName

For general printout the Display class can be used.