DataDog / ansible-datadog-callback

Ansible callback to get stats & events directly into Datadog http://datadoghq.com
MIT License
93 stars 47 forks source link

Port to Ansible 2 #13

Closed willmore closed 8 years ago

willmore commented 8 years ago

Added new file datadog_callback_ansbile2.py which is a copy of datadog_callback.py modified to work with Ansible 2.

This commit is a quick attempt to maintain Ansible 2 compatibility. The V1 version has not been modified at all, and there has been no attempt to normalize the interaction with DataDog between the two versions - a big DRY violation. However, Ansible 2 works and refactoring can be done as needed/desired.

Modification began with following porting guidance: https://docs.ansible.com/ansible/porting_guide_2.0.html

Minor other adjustments were maded following examples: https://github.com/ansible/ansible/tree/devel/lib/ansible/plugins/callback

joffotron commented 8 years ago

Hi @willmore @irabinovitch - having a bit of trouble with this on our buildservers, we're seeing

 [WARNING]: Failure when attempting to use callback plugin (</tmp/ops_e40c9b8c-
6cbb-4018-a8f1-dc79e85b6a80/ansible/playbooks/callback_plugins/datadog_callback
_ansible2.CallbackModule object at 0x7f6816d47c50>): [Errno 2] No such file or
directory

and

 [WARNING]: Failure when attempting to use callback plugin (</tmp/ops_e40c9b8c-
6cbb-4018-a8f1-dc79e85b6a80/ansible/playbooks/callback_plugins/datadog_callback
_ansible2.CallbackModule object at 0x7f6816d47c50>): 'module_name'

Any ideas as to how I can even start to debug this?

panophobicPanda commented 8 years ago

Thanks @willmore , this was very helpful.

I added a few things for my personal enjoyment:

  1. Added print statement for pip requirements
  2. Check ansible version, if less then 2, exit before failure
  3. Changed user for event from remote_user to my shell user

If anyone wants these, here is some code.... print statements at start:

import getpass
from os import popen
print("Datadog notifications enabled, be sure you meet these requirements: pip install datadog pyyaml && ansible > 2.0")
print("Your ansible version is:")
ansible_version_long = os.popen("ansible --version | head -n1 | awk '{print $2}'").read()
print(ansible_version_long)

exit if ansible < 2 :

ansible_version_major = int(os.popen("ansible --version | head -n1 | awk '{print $2}' | cut -d . -f 1").read())
if ansible_version_major >= 2:
... all the code stuff ....
else:
        print "ansible_version >= 2.0 required for datadog notifications, remove ansible-core/callback_plugins folder to continue; there is no smooth way to handle this, sorry"
        exit()

Change remote_user to shell_user:

        #                self._options.remote_user,
                        getpass.getuser(),
oryband commented 8 years ago

any update on this? almost 2 months have past and ansible 2 is gaining popularity

oryband commented 8 years ago

possible duplicate of #11 ?

olivielpeau commented 8 years ago

Thanks @willmore!

I'm working on testing this PR (along with #11) and merging the changes into the current callback (I'd like to keep one callback file for both Ansible 1 and 2). I should have something ready by the end of the week.

cc @oryband

olivielpeau commented 8 years ago

Closed by #16, thanks @willmore!

willmore commented 8 years ago

@olivielpeau happy to be of help. Thanks for adding the Ansible 2 support!

oryband commented 8 years ago

@joffotron i'm having a similar issue, opened a different ticket: #18