ansible

Ansible: How to print WARNINGs from playbook?


Can I print a warning message from Ansible? Like as Ansible does for an internal warning:

[WARNING]: Ignoring invalid attribute: xx

The targeted use are warning, that are not an error, so they should not end the playbook execution, but they should be clearly visible (in standard Ansible purple color).

Example usage:

  1. I have some hardcoded URL of the latest release.
  2. The playbook downloads the latest avaiable URL.
  3. And print warning if the URLs differs.
  4. As the source is not trusted, the downloaded URL is should be used only for comparison, but not used directly.

Solution

  • Based on your question it seems like you may want to fail the playbook if you don't trust the supplied URL but to answer your question about generating

    [WARNING]: <supplied text>

    messages the only way I know of to do this is by either your own ansible module or by a plugin.

    Your module or plugin would make the URL comparison you described and issue an appropriate message.

    In an ansible module the module object that you create has a warn function that you call like: module.warn('your text')

    In a plugin, your code will generate a Display object and that object will have a warning function that you call like: display.warning('your text').

    If your goal is simply to have an ansible purple warning message vs what you can generate via the debug module this seems like a lot of work.