Skip to content

Conversation

@szponek
Copy link
Contributor

@szponek szponek commented Jul 18, 2017

Primarily for #10 but also partially solves #4

Supports only Ansible >= 2

@mkporwit
Copy link

Would be great if this could be merged finally

@hush-hush hush-hush self-requested a review December 7, 2017 20:24
@hush-hush hush-hush self-assigned this Dec 7, 2017
@hush-hush hush-hush force-pushed the source-api-key-from-vault branch from 9116406 to 9517a5b Compare December 12, 2017 21:02
@hush-hush hush-hush removed their request for review December 12, 2017 21:02
Copy link
Member

@olivielpeau olivielpeau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

made a few comments, looks good overall, @hush-hush let me know what you think!

self._options = cli.options

# self.playbook is either set by Ansible (v1), or by us in the `playbook_start` callback method (v2)
# self.playbook is either set in the `v2_playbook_on_start` callback method
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.playbook is either set -> self.playbook is set

# self.playbook is either set in the `v2_playbook_on_start` callback method
self.playbook = None
# self.play is either set by Ansible (v1), or by us in the `playbook_on_play_start` callback method (v2)
# self.play is either set in the `playbook_on_play_start` callback method
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.play is either set -> self.play is set

getpass.getuser(),
self._inventory_name),
event_type='start',
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

by moving this logic (reading config + sending start event) from v2_playbook_on_start to v2_playbook_on_play_start, the callback sends a start event for every play in a playbook which is confusing given the contents of the event.

If I understand correctly we can't extract the api key sooner since we can't access the hostvars in v2_playbook_on_start, is that correct? If there's no workaround we should update the event here so that it says the the play has started, not the playbook :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, renaming the event to play seems the best.


# Set up API client and send a start event
if not self.disabled:
datadog.initialize(api_key=api_key, api_host=url)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this work if it's called multiple times? (i.e. when the playbook has multiple plays?)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the latest call reset the key/url.

@hush-hush hush-hush force-pushed the source-api-key-from-vault branch from 9517a5b to a601edc Compare December 19, 2017 18:27
Copy link
Member

@olivielpeau olivielpeau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One last detail, feel free to merge once it's addressed! 👍


self.send_playbook_event(
'Ansible play "{0}" started by "{1}" against "{2}"'.format(
self._playbook_name,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be self.play.name. Could also be worth keeping the playbook name in the message (could be Ansible play "{self.play.name}" started in playbook "{self._playbook_name}" by [...])

@hush-hush hush-hush force-pushed the source-api-key-from-vault branch from a601edc to e3896fc Compare December 22, 2017 19:39
@hush-hush hush-hush merged commit a7c4f10 into DataDog:master Dec 22, 2017
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.

4 participants