Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect user-specified stdout callback #387

Merged
merged 1 commit into from
Feb 14, 2020

Conversation

AlanCoding
Copy link
Member

No description provided.

@strider
Copy link

strider commented Dec 9, 2019

Tested this PR because I need it and it works as expected! +1

Copy link

@cloudnull cloudnull left a comment

Choose a reason for hiding this comment

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

👍 this seems to work as expected

@strider
Copy link

strider commented Jan 2, 2020

Hi @AlanCoding,
Any chance to get this PR merged ASAP?

@AlanCoding
Copy link
Member Author

While this is probably functional, I don't think a near-term merge is viable. Here is what I would like to do and have been pitching to people when I get a chance:

The content in https://github.com/ansible/ansible-runner/tree/master/ansible_runner/display_callback is shared code in multiple display callbacks (pretty much just job vs. ad hoc commands). The imports work the way they do today because this was all written before Ansible supported user-defined module_utils paths.

This PR does some ugly stuff juggling the DOCUMENTATION string because of the way that imports are done. If we restructure the code to the more proper format without PATH hacks, then we won't need that, and this feature will look almost trivial.

However, adding to the module_utils paths will almost certain break some use cases where the user is already using some custom module_utils paths. So we need to pull in some other code (originally done in AWX) to respect user-defined configs when ansible-runner itself relies on some config vars for basic operation.

So basically, I want these two other items in to pay down some tech debt before truly supporting this. I do very strongly want to do those. It is viable, but less trivial than the hacky stuff here.

@cloudnull
Copy link

Hi @AlanCoding, maybe we could sync up on IRC (strider, cloudnull), or on the mailing list, to talk about how we can help. We're now using ansible-runner within the OpenStack TripleO project and having the ability to set user defined callbacks is important to us. If we can help usher this feature along by working on the other two items we'd be happy to do so.

@ansible-zuul
Copy link
Contributor

ansible-zuul bot commented Feb 10, 2020

Build succeeded.

@AlanCoding
Copy link
Member Author

I'm ready to take this out of draft and call it ready for review. Before I do that, I will squash commits, but I made this branch to preserve this prior history:

https://github.com/ansible/ansible-runner/compare/devel...AlanCoding:stdout_callback_backup?expand=1

So after this comment, cleanup of this PR will start.

Create new integration test data folder
  this contains folders of runnable content
  contains example with selective callback
  contains example not printing skipped hosts

Fix bugs combining display callbacks due to call pattern
  if parent class took var as kwarg, then passing as arg
  will stop working when another parent is added
  in the inheritance chain

Restructure DOCUMENTATION management
  better align with user-specified display callback

Delete parameterization to test aggregate callback
  gave false positives and generally did not work
  replaced with new test and data example
@ansible ansible deleted a comment from ansible-zuul bot Feb 10, 2020
@ansible ansible deleted a comment from ansible-zuul bot Feb 10, 2020
@ansible ansible deleted a comment from ansible-zuul bot Feb 10, 2020
@ansible ansible deleted a comment from ansible-zuul bot Feb 10, 2020
@ansible ansible deleted a comment from ansible-zuul bot Feb 10, 2020
@ansible ansible deleted a comment from ansible-zuul bot Feb 10, 2020
@ansible ansible deleted a comment from ansible-zuul bot Feb 10, 2020
@ansible ansible deleted a comment from ansible-zuul bot Feb 10, 2020
@ansible ansible deleted a comment from ansible-zuul bot Feb 10, 2020
def get_documentation(cls):
if hasattr(cls, 'PROXY_DOCUMENTATION'):
return cls.PROXY_DOCUMENTATION
return BASE_DOCUMENTATION % cls.CALLBACK_NAME
Copy link
Member Author

Choose a reason for hiding this comment

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

My ears are open if someone wants to suggest a more beautiful way of creating the DOCUMENTATION string in this specific logic.

The "perfect" solution would be for awx_display and minimal to both extend from the same doc_fragment (which would still need to be overwritten by the user callback, if present). But that won't be available until we are fully in the world of collections. So to me, the general thing being doing here seems fully justifiable.

@@ -374,7 +404,7 @@ def v2_runner_on_failed(self, result, ignore_errors=False):
event_loop=self._get_event_loop(result._task),
)
with self.capture_event_data('runner_on_failed', **event_data):
super(BaseCallbackModule, self).v2_runner_on_failed(result, ignore_errors)
super(BaseCallbackModule, self).v2_runner_on_failed(result, ignore_errors=ignore_errors)
Copy link
Member Author

Choose a reason for hiding this comment

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

in Ansible core, these are kwargs, not args. Thus the change.

@@ -195,6 +195,9 @@ def prepare(self):
if python_path and not python_path.endswith(':'):
python_path += ':'
self.env['ANSIBLE_CALLBACK_PLUGINS'] = ':'.join(filter(None,(self.env.get('ANSIBLE_CALLBACK_PLUGINS'), callback_dir)))
# If stdout callback specified, pass info for this stdout callback plugin to subclass it
if 'ANSIBLE_STDOUT_CALLBACK' in self.env and self.env['ANSIBLE_STDOUT_CALLBACK'] not in ('awx_display', 'minimal'):
self.env['RUNNER_STDOUT_CALLBACK_PROXY'] = self.env['ANSIBLE_STDOUT_CALLBACK']
Copy link
Member Author

Choose a reason for hiding this comment

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

Needed this name RUNNER_STDOUT_CALLBACK_PROXY to be very specific. It could have a 20 digit uuid in its name for all I care, it's only passing it from parent context to child context and is a single static string.

- name: Reach out to the unreachable host
ping:
vars:
ansible_host: 'invalid.invalid'
Copy link
Member Author

Choose a reason for hiding this comment

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

Somewhere else I'm going with this - I want to test @wenottingham's #405 with it, because I'm worried about our ability (my ability) to correctly identify all task-ending callback types.

- name: Reach out to the unreachable host
ping:
vars:
ansible_host: 'invalid.invalid'
Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, I don't like the duplication either, but runner right now does not like to combine programatic and file inputs, so that's why it ended up like this.

@AlanCoding AlanCoding marked this pull request as ready for review February 10, 2020 16:51
@ansible-zuul
Copy link
Contributor

ansible-zuul bot commented Feb 10, 2020

Build succeeded.

Copy link
Contributor

@ryanpetrello ryanpetrello left a comment

Choose a reason for hiding this comment

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

This seems pretty reasonable to me.

@@ -0,0 +1,15 @@
### Ansible Runner Test Data Directories

Subfolders in this directory should contain test cases in the form of
Copy link
Member

Choose a reason for hiding this comment

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

👍

@ansible-zuul
Copy link
Contributor

ansible-zuul bot commented Feb 14, 2020

Build succeeded (gate pipeline).

@ansible-zuul ansible-zuul bot merged commit 9e7e75d into ansible:master Feb 14, 2020
@AlanCoding
Copy link
Member Author

This was mistakenly merged into the master branch, which changed to the devel branch at some point. That's not good.

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.

None yet

5 participants