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

infra.ah_configuration.ah_api plugin gives "'AHAPIModule' object has no attribute '_debug'" #325

Closed
Alex-Bron opened this issue Oct 15, 2023 · 2 comments
Labels
bug Something isn't working new

Comments

@Alex-Bron
Copy link

Summary

I am trying to use the infra.ah_configuration.ah_api plugin to retrieve the number of collections in a certain collection repository. So the code for this is:

- name: Print the number of rh-certified collections
  ansible.builtin.debug:
    msg: "{{ query('infra.ah_configuration.ah_api', 'collections', 'repository=rh_certified', 'host=https://' + ah_hostname, 'username=' + ah_username, 'password=' + ah_password) }}"

However running this playbook always results in an error:

TASK [handle_collections : Print the number of rh-certified collections] ***
Sunday 15 October 2023  19:02:03 +0000 (0:00:03.204)       0:00:07.659 ******** 
fatal: [hub]: FAILED! => {"msg": "An unhandled exception occurred while running the lookup plugin 'infra.ah_configuration.ah_api'. Error was a <class 'AttributeError'>, original message: 'AHAPIModule' object has no attribute '_debug'. 'AHAPIModule' object has no attribute '_debug'"}

I changed the parameters to match the exact examples, but always get this AHAPImodule error. Is there a prerequisite that I'm not aware of, or is the code really broken?

Issue Type

  • Bug Report

Ansible, Collection, Private Automation Hub details

ansible --version
ansible [core 2.14.9]
  config file = /home/alex/git/aap/collections/ansible_collections/infra/ah_configuration/ansible.cfg
  configured module search path = ['/home/alex/git/aap/collections/ansible_collections/infra/ah_configuration/plugins/modules']
  ansible python module location = /usr/lib/python3.9/site-packages/ansible
  ansible collection location = /home/alex/git/aap/collections/ansible_collections/infra/ah_configuration/collections
  executable location = /usr/bin/ansible
  python version = 3.9.16 (main, May 31 2023, 12:21:58) [GCC 8.5.0 20210514 (Red Hat 8.5.0-18)] (/usr/bin/python3.9)
  jinja version = 3.1.2
  libyaml = True

ansible-galaxy collection list
# /usr/share/ansible/collections/ansible_collections
Collection               Version
------------------------ -------
redhat.rhel_mgmt         1.1.0  
redhat.rhel_system_roles 1.21.2 

# /home/alex/git/aap/collections/ansible_collections
Collection                          Version
----------------------------------- -------
ansible.posix                       1.5.4  
community.general                   7.5.0  
infra.ah_configuration              2.0.4  
infra.controller_configuration      2.5.2  
redhat_cop.controller_configuration 2.2.4

Private Automation Hub version 2.4-2.1 (Hub version 4.7.3
  • ansible installation method: OS package from ansible automation platform 2.4 subscription at Red Hat

OS / ENVIRONMENT

Target OS: Red Hat Enterprise Linux 8 (part of Ansible Automation Platform 2.4 installation)

Desired Behavior

I would like to retrieve information from my Automation Hub for further use\

Actual Behavior

I always get the error
Error was a <class 'AttributeError'>, original message: 'AHAPIModule' object has no attribute '_debug'.

Please give some details of what is actually happening.
Include a [minimum complete verifiable example] with:

  • playbook / task
  • configuration file / list
  • error
- name: Sync Red Hat Certified repo
  infra.ah_configuration.collection_repository_sync:
    name: rh-certified
    wait: true
    ah_host: "{{ ah_hostname }}"
    ah_username: "{{ ah_username }}"
    ah_password: "{{ ah_password }}"
    validate_certs: "{{ ah_validate_certs | default(true) }}"
  register: rh_certified_sync

- name: Print the number of rh-certified collections
  ansible.builtin.debug:
    msg: "{{ query('infra.ah_configuration.ah_api', 'collections', 'repository=rh_certified', 'host=https://' + ah_hostname, 'username=' + ah_username, 'password=' + ah_password) }}"
    msg: "Users: {{ query('infra.ah_configuration.ah_api', 'users', return_all=true) | map(attribute='username') | list }}"

STEPS TO REPRODUCE

- name: Print the number of rh-certified collections
  ansible.builtin.debug:
    msg: "{{ query('infra.ah_configuration.ah_api', 'collections', 'repository=rh_certified', 'host=https://' + ah_hostname, 'username=' + ah_username, 'password=' + ah_password) }}"
    msg: "Users: {{ query('infra.ah_configuration.ah_api', 'users', return_all=true) | map(attribute='username') | list }}"
ah_host: automation hub hostname
ah_username: user with sufficient privileges on automation hub
ah_password: password of that user
@Alex-Bron Alex-Bron added bug Something isn't working new labels Oct 15, 2023
@akocot
Copy link

akocot commented Oct 30, 2023

@Alex-Bron I faced the same issue.

I was able to make it work by using ENV variables instead of playbook variables:
AH_HOST, AH_USERNAME, AH_PASSWORD

Looks like the lookup plugin doesn't load the playbook/extra variables properly.

@Alex-Bron
Copy link
Author

It was my bad - I can close this issue. I should not have put the "'host=https://' + ah_hostname, 'username=' + ah_username, 'password=' + ah_password" between quotes.

So correct syntax here was:
__rh_certified: {{ lookup('infra.ah_configuration.ah_api', 'collections', 'rh-certified', host=ah_hostname, username=ah_username, password=ah_password, return_all=true) }}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working new
Projects
None yet
Development

No branches or pull requests

2 participants