Skip to content

Conversation

@willmore
Copy link

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

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
@irabinovitch irabinovitch mentioned this pull request Apr 19, 2016
@joffotron
Copy link

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
Copy link

panophobicPanda commented May 13, 2016

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
Copy link

oryband commented May 31, 2016

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

@oryband
Copy link

oryband commented May 31, 2016

possible duplicate of #11 ?

@olivielpeau
Copy link
Member

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
Copy link
Member

Closed by #16, thanks @willmore!

@olivielpeau olivielpeau closed this Jun 2, 2016
@willmore
Copy link
Author

willmore commented Jun 2, 2016

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

@oryband
Copy link

oryband commented Jun 6, 2016

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants