5

I have recently been alerted to the existence of ansible callbacks, which appear to be a way to modify some of the defaults under given conditions.

However, I have scoured the ansible documentation as well as a few books, google and the source code, but for the life of me I cannot find the answer to this simple question:

How does one change the configuration items that affect the beahavior of ansible callbacks?

-E.g: the mail callback appears, looking at the code, to be able to be configured to send mail to a configurable email address through a configurable SMTP host. How/where/when should these be specified?

But, if the mail callback (and the base class for callbacks), are anything to go by, there actually appears to be NO standard configuration mechanism..

Mail, for instance, gets SMTPHOST from an environment variable if it's there, and to: appears nailed to <root> (no good if the mailer insists on blah@fully.qualified.dom.ain as valid addresses).

  • You can read group and host vars in the callback, but if I understand you correctly, you want to change the configuration on the fly during the play. Is that correct? – udondan Apr 29 '16 at 14:39
  • That's it (viz. I want to email someone else rather than root, etc.) Of course if I wrote my own callback, I would very well be able to do as I please, like reading a cfg file and access the universe through ansible's API, but that's somehow beside the point. As they appear to me now, callbacks are blackboxes whose only documentation is the code. The main site mentions them only in the developer section, for instance. – Alien Life Form Apr 29 '16 at 15:00
0

Looking at the docs and some of the existing callback plugins, one method appears to be using the environment.

For example, the jabber callback simply uses 'more' env vars to allow more granular configuration.

This seems to be the case for a lot of the other callbacks, and I couldn't find any examples of using ansible variables for such purposes.

That, though, is presumably possible - checking the CallbackBase#_get_item method, it seems possible to go through the ansible vars to get at whatever config might be appropriate.

However, I do think using environment variables seems to be some form of standard - although I agree it isn't exactly a strongly defined standard if indeed it is one

As you say, the callbacks are a little obscure, and it may be this is one of those 'if you need it, you will know what to do' areas in ansible.

In the case of the mail callback, it may be your best bet is to just subclass the existing plugin to add the config variables you feel you might want.

I personally get the sense that callbacks are by and large considered an advanced feature, and that many of the available callbacks are more intended as a base (and in some cases, as a quick hack to get something) to be extended by those needing their functionality. But that is purely a feeling.

-1

I'm not shure if I get you correctly but I think youre right about the black boxes idear of the callbacks or also official modules,

I image the python modules like unix "commands" they can be very different and accept different options and the architecture makes it difficult for the ansible team to do big architectural changes since it would mean modifying/extending all the existing modules(such as the much demanded progress reports on running modules https://github.com/ansible/ansible/issues/3887 which means they have no way of checking if a module is stuck)

To have control of the configuration or change/persist them I choose another apporach than only writing callbacks.

I wrote a layer around ansible by using the dynamic inventory capability and I used Output callback plugins to format the output into json to be able to parse the output of a successfull run and save changes states / data back into my inventory management programm. That way I can change variables or even add hosts in the playbook with simple tasks call and automatically apply them back to my inventory without needing to modify or extend ansible a lot and stay relatively compatible to future versions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.