2

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?

Wolfson
  • 1,187
  • 17
  • 22
  • Does this answer your question? [Ansible: How to print WARNINGs from playbook?](https://stackoverflow.com/a/48036628/6771046) – U880D May 05 '23 at 16:16
  • 1
    @U880D even though the question there doesn't explicitly ask for a warning out of a custom module, the linked answer does explain how to do that, so yes :) – Wolfson May 05 '23 at 16:40

1 Answers1

3

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.

Wolfson
  • 1,187
  • 17
  • 22