Specify the specific callback to be used in the playbook

I created different players for different operations in .

And I also created different callback scripts for different kinds of Playbooks (and packaged them with Ansible and installed).

Playbores will be called up from various tasks in / cron scripts.

Now you can specify a specific callback script to call a specific piece ? (Perhaps with a command line argument?)

What is happening now, all callback scripts are called for every play.

I can not put a callback script relative to the location / folder in the playlist because it is already packed inside an unoccupied package. In addition, all players are in the same place.

I am fine with modifying a small source code to adapt it if necessary.

+6
source share
2 answers

After going through the Ansible code, I was able to solve it using below ...

In each callback_plugin you can specify self.disabled = True , and callback will not be called at all ...

In addition, when calling the playbook, it is possible to parse additional arguments as a key=value pair. It will be part of the playbook object as an extra_vars field.

So, I did something like this in callback_plugin .

 def playbook_on_start(self): callback_plugins = self.playbook.extra_vars.get('callback_plugin', '') // self.playbook is populated in your callback plugin by Ansible. if callback_plugins not in ['email_reporter', 'all']: self.disabled = True 

And when calling the playbook, I can do something like

 ansible-playbook -e callback_plugin=email_reporter //Note -e is the argument prefix key for extra vars. 
+3
source

If with callback scripts you mean callback plugins , you can decide in which plugins if some tutorial should trigger some action.

In the playbook_on_play_start method, you have a play name that you can use to decide whether to process further notifications or not.

playbook_on_stats then called at the end of the tutorial.

 SHOULD_TRIGGER = false class CallbackModule(object): def playbook_on_play_start(self, name): if name == "My Cool Play": SHOULD_TRIGGER = true def playbook_on_stats(self, stats): if SHOULD_TRIGGER == true: do something cool 

Please note that playbook_on_play_start is called for every play in your playbook, so you can call it several times.

+1
source

All Articles