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_collection can't delete collections from Private Automation Hub #410

Open
Alex-Bron opened this issue Jun 19, 2024 · 0 comments
Labels
bug Something isn't working inactive new

Comments

@Alex-Bron
Copy link

Summary

Using infra.ah_configuration.ah_collection with state 'absent' as to delete collections from a repository appears not to be working. There are a couple of bugs present, and actual deletion does not happen.

Issue Type

  • Bug Report

Ansible, Collection, Private Automation Hub details

ansible --version
ansible [core 2.15.10]

Private Automation Hub version
Server version: 4.9.2
Pulp Ansible Version: 0.20.7
Pulp Container Version: 2.15.5
Pulp Core Version: 3.28.27
Ansible Automation Platform: 2.4
  • ansible installation method: one of source, pip, OS package, EE
    EE as part of Automation Platform

OS / ENVIRONMENT

Not applicable: management of Private Automation Hub via Ansible

Desired Behavior

Using the task:

    - name: Delete all found collections from the repos
      infra.ah_configuration.ah_collection:
        ah_host: "{{ ah_url }}"
        ah_token: "{{ ah_token }}"
        namespace: "{{ this_collection.namespace }}"
        name: "{{ this_collection.name }}"
        state: absent

I want to delete a specific collection from the system.

Actual Behavior

First error that happens is stating:

ansible_collections/infra/ah_configuration/plugins/modules/ah_collection.py\", line 146, in main\r\nAttributeError: 'NoneType' object has no attribute 'split'\r\n

It turns out that the parameter 'auto_approve' is checked regardless of the parameter 'state'; by setting 'auto_approve' to 'false' I can work around this problem.

With the added 'auto_approve: false' the task will run, but it will either return 'ok' for some collections, or it will raise an exception for others. Output of the exception is:

Traceback (most recent call last):\r\n  File \"/home/ansible/.ansible/tmp/ansible-tmp-1718827337.1524935-36-220491761771436/AnsiballZ_ah_collection.py\", line 107, in <module>\r\n    _ansiballz_main()\r\n  File \"/home/ansible/.ansible/tmp/ansible-tmp-1718827337.1524935-36-220491761771436/AnsiballZ_ah_collection.py\", line 99, in _ansiballz_main\r\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\r\n  File \"/home/ansible/.ansible/tmp/ansible-tmp-1718827337.1524935-36-220491761771436/AnsiballZ_ah_collection.py\", line 48, in invoke_module\r\n    run_name='__main__', alter_sys=True)\r\n  File \"/usr/lib64/python3.6/runpy.py\", line 205, in run_module\r\n    return _run_module_code(code, init_globals, run_name, mod_spec)\r\n  File \"/usr/lib64/python3.6/runpy.py\", line 96, in _run_module_code\r\n    mod_name, mod_spec, pkg_name, script_name)\r\n  File \"/usr/lib64/python3.6/runpy.py\", line 85, in _run_code\r\n    exec(code, run_globals)\r\n  File \"/tmp/ansible_infra.ah_configuration.ah_collection_payload_lfzhbfyb/ansible_infra.ah_configuration.ah_collection_payload.zip/ansible_collections/infra/ah_configuration/plugins/modules/ah_collection.py\", line 227, in <module>\r\n  File \"/tmp/ansible_infra.ah_configuration.ah_collection_payload_lfzhbfyb/ansible_infra.ah_configuration.ah_collection_payload.zip/ansible_collections/infra/ah_configuration/plugins/modules/ah_collection.py\", line 163, in main\r\nKeyError: 'task'\r\n"

It seems that this has to do with whether or not a collection has dependencies. However for the collections where the task returns 'ok', nothing is actually deleted.

STEPS TO REPRODUCE

Run the following playbook against a Private Automation Hub - fill in the hostname, username and password of the hub.

- name: Playbook to cleanup collections from Private Automation Hub
  hosts: hub
  gather_facts: false
  run_once: true
  vars:
    aap_platform_ah_username: "{{ uc_content_1 }}"
    aap_platform_ah_password: "{{ uc_content_2 }}"
    ah_collection_repos:
      - community
  tasks:
    - name: Get an authentication token from the Hub
      infra.ah_configuration.ah_token:
        ah_host: "{{ ah_url }}"
        ah_username: "{{ lookup('file', aap_platform_ah_username) }}"
        ah_password: "{{ lookup('file', aap_platform_ah_password) }}"
        state: present
      no_log: true
    - name: Query the Automation Hub for all collections it knows
      ansible.builtin.set_fact:
        ah_collections: |
          {{ ah_collections | default([]) +
            lookup('infra.ah_configuration.ah_api', 'collections', this_repo,
            host=ah_url,
            username=lookup('file', aap_platform_ah_username),
            password=lookup('file', aap_platform_ah_password),
            return_all=true) }}
      loop: "{{ ah_collection_repos }}"
      loop_control:
        loop_var: this_repo
      no_log: true
    - name: Delete all found collections from the repos
      infra.ah_configuration.ah_collection:
        ah_host: "{{ ah_url }}"
        ah_token: "{{ ah_token }}"
        namespace: "{{ this_collection.namespace }}"
        name: "{{ this_collection.name }}"
        state: absent
        auto_approve: false
      loop: "{{ ah_collections }}"
      loop_control:
        loop_var: this_collection
    - name: Delete this token
      infra.ah_configuration.ah_token:
        ah_host: "{{ ah_url }}"
        ah_token: "{{ ah_token }}"
        state: absent
@Alex-Bron Alex-Bron added bug Something isn't working new labels Jun 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working inactive new
Projects
None yet
Development

No branches or pull requests

2 participants