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

[Tech debt] Put the standard out callback into a collection #889

Open
AlanCoding opened this issue Oct 27, 2021 · 1 comment
Open

[Tech debt] Put the standard out callback into a collection #889

AlanCoding opened this issue Oct 27, 2021 · 1 comment

Comments

@AlanCoding
Copy link
Member

The standard out callback for this project is extremely old, and has not been updated to changes that Ansible content have been adoption elsewhere.

Proposal: Place the awx_display (and minimal) callback plugins in a collection. Enable use of this collection, as opposed to the callback plugin.

I previously made a small attempt to convert this into a collection at #409, but it's a project of significant scope and impact.

Python import hacks resolvable by module_utils

The callback receiver puts code in multiple modules, and it allows for this by modifying sys.path. (the mention of the awx/lib folder is out of date, was before the split from awx)

# Add awx/lib to sys.path.
awx_lib_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
if awx_lib_path not in sys.path:
sys.path.insert(0, awx_lib_path)

Now, you can much more easily break your code into multiple modules by putting modules into module_utils inside of a collection.

This would also probably resolve the import issue addressed with the other hack for import order.

# ansible.plugins.callback.minimal when being loaded as the minimal plugin. Ugh.
minimal_plugin = os.path.join(os.path.dirname(ansible.__file__), 'plugins', 'callback', 'minimal.py')
exec(compile(open(minimal_plugin, "rb").read(), minimal_plugin, 'exec'))

Testing the plugin via ansible-test

Many other projects are making heavy use of ansible-test checks. You can do unit and integration tests. Unit tests would probably be useful for this project.

Enabling the collection as opposed to the plugin

We use an environment variable to enable the standard out callback.

self.env['ANSIBLE_STDOUT_CALLBACK'] = 'awx_display'

If this is maintained as a collection, we would change this to modify ANSIBLE_COLLECTIONS_PATH instead. That option has some risk that custom collection paths in the user's ansible.cfg could get overwritten. This is an additional challenge, which would be resolved by parsing the config file, or by placing the collection in a special place in execution environment images.

@AlanCoding
Copy link
Member Author

I missed this:

self.env['PYTHONPATH'] = ':'.join([python_path, callback_dir])

We add the callback dir to the PYTHONPATH in the ansible subprocess. Only if it's not containerized. That sounds like it is based on incorrect assumptions (it may not be necessary right now), but it's obviously not good.

@samdoran samdoran added the needs_triage New item that needs to be triaged label Nov 1, 2021
@samdoran samdoran removed the needs_triage New item that needs to be triaged label Nov 9, 2021
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

No branches or pull requests

2 participants