ansible / galaxy_collection

Collection of modules and roles to configure Automation Hub
GNU General Public License v3.0
58 stars 54 forks source link

Publishing collections fails on the second run #397

Open myllynen opened 6 months ago

myllynen commented 6 months ago

With a local automation hub and collection version 2.0.6 + PR 386 using the following with the needed namespace created earlier the publish role works on the first run but fails on the second run:

ah_collections:
  - collection_name: myllynen.rhel_ansible_roles
    git_url: https://github.com/myllynen/rhel-ansible-roles
    version: v1.8.0
  - collection_name: myllynen.rhel_image
    git_url: https://github.com/myllynen/rhel-image
    version: v1.3.1
TASK [infra.ah_configuration.publish : Publish Collection | Wait for finish the publish creation] **********
...
FAILED - RETRYING: [localhost]: Publish Collection | Wait for finish the publish creation (45 retries left).                                                                                                                                  
failed: [localhost] (item={'failed': 0, 'started': 1, 'finished': 0, 'ansible_job_id': 'j587721783571.6249', 'results_file': '/home/admin/.ansible_async/j587721783571.6249', 'changed': False, '__ah_collection_file': '/var/tmp/myllynen.rhel_ansible_roles/myllynen-rhel_ansible_roles-1.8.0.tar.gz', 'ansible_loop_var': '__ah_collection_file'}) =>                                                                                                                                    
    __publish_job_async_result_item:                                                                                                                                                                                                          
        __ah_collection_file: /var/tmp/myllynen.rhel_ansible_roles/myllynen-rhel_ansible_roles-1.8.0.tar.gz                                                                                                                                   
        ansible_job_id: j587721783571.6249                                                                                                                                                                                                    
        ansible_loop_var: __ah_collection_file                                                                                                                                                                                                
        changed: false                                                                                                                                                                                                                        
        failed: 0                                                                                                                                                                                                                             
        finished: 0                                                                                                                                                                                                                           
        results_file: /home/admin/.ansible_async/j587721783571.6249                                                                                                                                                                           
        started: 1                                                                                                                                                                                                                            
    ansible_job_id: j587721783571.6249                                                                                                                                                                                                        
    ansible_loop_var: __publish_job_async_result_item                                                                                                                                                                                         
    attempts: 7                                                                                                                                                                                                                               
    changed: false                                                                                                                                                                                                                            
    finished: 1                                                                                                                                                                                                                               
    msg: |-                                                                                                                                                                                                                                   
        Upload of collection failed: insert or update on table "core_contentartifact" violates foreign key constraint "core_contentartifact_artifact_id_f5d9a66b_fk_core_artifact__id"                                                        
        DETAIL:  Key (artifact_id)=(018f9551-4b04-79eb-a59a-d0ed441adcab) is not present in table "core_artifact".                                                                                                                            
    results_file: /home/admin/.ansible_async/j587721783571.6249                                                                                                                                                                               
    started: 1                                                                                                                                                                                                                                
    stderr: ''                                                                                                                                                                                                                                
    stderr_lines: <omitted>                                                                                                                                                                                                                   
    stdout: ''                                                                                                                                                                                                                                
    stdout_lines: <omitted>                                                                                                                                                                                                                   
FAILED - RETRYING: [localhost]: Publish Collection | Wait for finish the publish creation (50 retries left).                                                                                                                                  
...
FAILED - RETRYING: [localhost]: Publish Collection | Wait for finish the publish creation (1 retries left).
failed: [localhost] (item={'failed': 0, 'started': 1, 'finished': 0, 'ansible_job_id': 'j92391990330.6269', 'results_file': '/home/admin/.ansible_async/j92391990330.6269', 'changed': False, '__ah_collection_file': '/var/tmp/myllynen.rhel_image/myllynen-rhel_image-1.3.1.tar.gz', 'ansible_loop_var': '__ah_collection_file'}) => 
    __publish_job_async_result_item:
        __ah_collection_file: /var/tmp/myllynen.rhel_image/myllynen-rhel_image-1.3.1.tar.gz
        ansible_job_id: j92391990330.6269
        ansible_loop_var: __ah_collection_file
        changed: false
        failed: 0
        finished: 0
        results_file: /home/admin/.ansible_async/j92391990330.6269
        started: 1
    ansible_job_id: j92391990330.6269
    ansible_loop_var: __publish_job_async_result_item
    attempts: 50
    changed: false
    finished: 0
    results_file: /home/admin/.ansible_async/j92391990330.6269
    started: 1
    stderr: ''
    stderr_lines: <omitted>
    stdout: ''
    stdout_lines: <omitted>

Looks like the role does not detect that the collection version already exist and then needlessly clones it, builds it, and tries to upload it. This causes issues with CaC/GitOps where ideally there could be only one yml file listing collections and collections could be updated individually as new versions become available. Thanks.

djdanielsson commented 6 months ago

so this isn't a bug this would be a change in how the role works itself, I am updating the labels to fit

myllynen commented 6 months ago

I'm not sure about the labels and classification but the hope here is that the role would be idempotent. Thanks.