Closed Alex-Bron closed 1 year ago
Hi @Alex-Bron
Thanks for raising this to attention. After checking I can see that ah_token is not actually supported for the ah_api lookup plugin (as the same as several of the modules due to the way it interacts with the API). I will raise a PR to fix the documentation for the plugin but in the meantime the workaround would be to directly apply the username and password to the plugin as follows:
- name: Next, query the Automation Hub for the rh-certified collections
ansible.builtin.debug:
msg: "Collections: {{ lookup('redhat_cop.ah_configuration.ah_api', 'collections', host=ah_hostname, username=ah_username, password=ah_password, return_all=true) }}"
Additionally, for the doc_fragment issue, there is not a great workaround for this as is a symptom of us moving the namespace of this collection. My advice would be to make use of the new location for the collection: infra.ah_configuration
as the redhat_cop
namespace will eventually be deprecated for this collection.
Thanks for the very swift replies to my issue. So I changed the namespace to infra (will redhat_cop.controller_configuration also be replaced by infra.controller_configuration?) and added my username and password to the ah_api lookup, however this returns an empty list although I'm sure there are collections present on my automation hub. Am I maybe doing something wrong here? Is my assumption incorrect that this ah_api lookup can be used to retrieve a list of collections present on the system? In the end I'd want to query for a list of collections from the rh-certified repository, as those should not be searched for in the community repository.
Code snippet:
- name: Next, query the Automation Hub for the rh-certified collections
ansible.builtin.debug:
msg: "Collections: {{ lookup('infra.ah_configuration.ah_api', 'collections', host=ah_hostname, username=ah_username, password=ah_password, return_all=true) }}"
Ah yes, looks like the API for this has changed. It seems this will only be pulling the published
collections now. I have raised an issue which will allow an additional term to be given which pulls from a specific repository (e.g. rh-certified). I'll write a PR up for this and we can try to get it in ASAP. Unfortunately for now, there is no way to query the list of collections under anything other than published
Ok, waiting for the 1.0.1 release then :-) I hope my approach makes sense: query all gitlab projects for their requirements.yml, carve out the rh-certified collections from that list, and add the remainder to the communities repository for syncing (I don't use "my own" collections so no reason to carve out also the published ones...)
That's a pretty neat solution to automatically work out what you need to sync, so definitely this update will help you out.
@Alex-Bron v1.0.1 has now been released here: https://galaxy.ansible.com/infra/ah_configuration
Hope this is now all fixed for you
Thanks Tom for the effort, downloaded the new collection and tested it and yes! I can get a json with all rh-certified collections. Will continue my quest for generating the community requirements from this (I really want to automate the automation as much as possible :-) )
Summary
When using the ah_api lookup plugin, tasks fail with message:
unknown doc_fragment(s) in file /home/alex/git/aap/collections/ansible_collections/redhat_cop/ah_configuration/plugins/lookup/ah_api.py: infra.ah_configuration.auth_plugin
When manually replacing infra.ah_configuration with redhat_cop.ah_configuration, tasksfail with message:An unhandled exception occurred while running the lookup plugin 'redhat_cop.ah_configuration.ah_api'. Error was a <class 'AttributeError'>, original message: 'dict' object has no attribute 'getheaders'. 'dict' object has no attribute 'getheaders'
Issue Type
Ansible, Collection, Private Automation Hub details
OS / ENVIRONMENT
Tasks run on localhost (RHEL8) against Private Automation Hub 2.3 on RHEL 8.7
Desired Behavior
I want to retrieve a list of collections from the rh-certified repository, so I can remove those from the list of requirements.yml entries which then can be configured in the communities repository. The way to retrieve the list of collections is by doing an ah_api lookup for collections on the private automation hub
Actual Behavior
Snippet of code used for this:
Task failure messages: When ah_api is still referring to the infra.ah_configuration collection:
When ah_api is modified to refer to redhat_cop.ah_configuration:
STEPS TO REPRODUCE
Use the code snippet from above to reproduce.