-
Notifications
You must be signed in to change notification settings - Fork 346
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
Conversation
3da093b
to
15a0814
Compare
Tested this PR because I need it and it works as expected! +1 |
There was a problem hiding this 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
Hi @AlanCoding, |
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. |
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. |
15a0814
to
cf16133
Compare
Build succeeded.
|
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
124cf23
to
1cc53bf
Compare
def get_documentation(cls): | ||
if hasattr(cls, 'PROXY_DOCUMENTATION'): | ||
return cls.PROXY_DOCUMENTATION | ||
return BASE_DOCUMENTATION % cls.CALLBACK_NAME |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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'] |
There was a problem hiding this comment.
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' |
There was a problem hiding this comment.
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' |
There was a problem hiding this comment.
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.
Build succeeded.
|
There was a problem hiding this 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Build succeeded (gate pipeline).
|
This was mistakenly merged into the master branch, which changed to the devel branch at some point. That's not good. |
No description provided.