log filename in a callback plugin

Hello,

In a callback plugin, I did parameter the filename to dipatch log files by host and ansible pid this way:
filename = ‘%s_%s’ % (host,os.getpid())

I would like to add the name of the playbook that is run, in example if I run the command: ansible-playbook test.yml, I would like to create this logfile: test_host_pid
in what structure and variable can I get the playbook name ?

Regards

I did modify my plugin this way:

def init(self):
super(CallbackModule, self).init()
self.playbook_name = None

if not os.path.exists(“./logs”):
os.makedirs(“./logs”)

  • def v2_playbook_on_start(self, playbook):
    self.playbook = playbook
    self.playbook_name = os.path.basename(self.playbook._file_name*)

def log(self, host, data):
filename = ‘%s_%s_%s’ % (self.playbook_name,host,os.getpid())
path = os.path.join(“./logs”, filename)