ansibleansible-module

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


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?


Solution

  • 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.