cannot get remote_user in a callback plugin

Hi all,

I am developing a callback plugin to print messages to hipchat when playbook starts and finishes, and some additional info like who is running the playbook. To get the username I tried 2 ways:

  1. cli.options.remote_user – outputs “None”.

  2. play.remote_user – outputs username only if remote_user is defined in a play. Unfortunately we don’t do this in our playbooks.

I also looked at hipchat (https://github.com/ansible/ansible/blob/devel/lib/ansible/plugins/callback/hipchat.py) and slack (https://github.com/ansible/ansible/blob/devel/lib/ansible/plugins/callback/slack.py#L155) callback plugins and it’s not working with Ansible 2.4.1.0:

hipchat

PLAY [aplay] ********************************************************************************************

[WARNING]: Failure using method (v2_playbook_on_play_start) in callback plugin (<ansible.plugins.callback.hipchat.CallbackModule object at 0x10dd0f5d0>): ‘Play’ object has no attribute ‘playbook’

#slack

PLAY [aplay] **********************************************************************************************
[WARNING]: Failure using method (v2_playbook_on_play_start) in callback plugin (<ansible.plugins.callback.hipchat2.CallbackModule object at 0x1092ba4d0>): ‘dict’ object has no attribute ‘remote_user’

How do I get username which runs the playbook in a callback plugin?

Thanks,

Igor