|
| 1 | +--- |
| 2 | +- name: Upload and create a distribution for an artifact |
| 3 | + hosts: seed |
| 4 | + vars: |
| 5 | + remote_pulp_url: "{{ stackhpc_release_pulp_url }}" |
| 6 | + remote_pulp_username: "{{ stackhpc_release_pulp_username }}" |
| 7 | + remote_pulp_password: "{{ stackhpc_release_pulp_password }}" |
| 8 | + repository_name: "{{ artifact_type }}-{{ openstack_release }}-{{ os_distribution }}-{{ os_release }}" |
| 9 | + pulp_base_path: "{{ artifact_type }}/{{ openstack_release }}/{{ os_distribution }}/{{ os_release }}" |
| 10 | + tasks: |
| 11 | + - name: Print artifact tag |
| 12 | + debug: |
| 13 | + msg: "artifact tag: {{ artifact_tag }}" |
| 14 | + |
| 15 | + - name: Get filename |
| 16 | + find: |
| 17 | + paths: "{{ artifact_path }}" |
| 18 | + patterns: "{{ file_regex }}" |
| 19 | + register: found_files |
| 20 | + |
| 21 | + - name: Upload an artifact |
| 22 | + pulp.squeezer.artifact: |
| 23 | + pulp_url: "{{ remote_pulp_url }}" |
| 24 | + username: "{{ remote_pulp_username }}" |
| 25 | + password: "{{ remote_pulp_password }}" |
| 26 | + file: "{{ found_files.files[0].path }}" |
| 27 | + state: present |
| 28 | + register: upload_result |
| 29 | + until: upload_result is success |
| 30 | + retries: 3 |
| 31 | + delay: 60 |
| 32 | + |
| 33 | + - name: Get sha256 hash |
| 34 | + ansible.builtin.stat: |
| 35 | + path: "{{ found_files.files[0].path }}" |
| 36 | + checksum_algorithm: sha256 |
| 37 | + register: file_stats |
| 38 | + |
| 39 | + - name: Create file content from artifact |
| 40 | + pulp.squeezer.file_content: |
| 41 | + pulp_url: "{{ remote_pulp_url }}" |
| 42 | + username: "{{ remote_pulp_username }}" |
| 43 | + password: "{{ remote_pulp_password }}" |
| 44 | + sha256: "{{ file_stats.stat.checksum }}" |
| 45 | + relative_path: "{{ found_files.files[0].path | basename }}" |
| 46 | + state: present |
| 47 | + register: file_content_result |
| 48 | + until: file_content_result is success |
| 49 | + retries: 3 |
| 50 | + delay: 5 |
| 51 | + |
| 52 | + - name: Ensure file repo exists |
| 53 | + pulp.squeezer.file_repository: |
| 54 | + pulp_url: "{{ remote_pulp_url }}" |
| 55 | + username: "{{ remote_pulp_username }}" |
| 56 | + password: "{{ remote_pulp_password }}" |
| 57 | + name: "{{ repository_name }}" |
| 58 | + state: present |
| 59 | + register: file_repo_result |
| 60 | + until: file_repo_result is success |
| 61 | + retries: 3 |
| 62 | + delay: 5 |
| 63 | + |
| 64 | + - name: Add content to file repo |
| 65 | + pulp.squeezer.file_repository_content: |
| 66 | + pulp_url: "{{ remote_pulp_url }}" |
| 67 | + username: "{{ remote_pulp_username }}" |
| 68 | + password: "{{ remote_pulp_password }}" |
| 69 | + repository: "{{ repository_name }}" |
| 70 | + present_content: |
| 71 | + - relative_path: "{{ found_files.files[0].path | basename }}" |
| 72 | + sha256: "{{ file_stats.stat.checksum }}" |
| 73 | + register: file_repo_content_result |
| 74 | + until: file_repo_content_result is success |
| 75 | + retries: 3 |
| 76 | + delay: 5 |
| 77 | + |
| 78 | + - name: Create a new publication to point to this version |
| 79 | + pulp.squeezer.file_publication: |
| 80 | + pulp_url: "{{ remote_pulp_url }}" |
| 81 | + username: "{{ remote_pulp_username }}" |
| 82 | + password: "{{ remote_pulp_password }}" |
| 83 | + repository: "{{ repository_name }}" |
| 84 | + state: present |
| 85 | + register: publication_details |
| 86 | + until: publication_details is success |
| 87 | + retries: 3 |
| 88 | + delay: 5 |
| 89 | + |
| 90 | + - name: Update distribution for latest version |
| 91 | + pulp.squeezer.file_distribution: |
| 92 | + pulp_url: "{{ remote_pulp_url }}" |
| 93 | + username: "{{ remote_pulp_username }}" |
| 94 | + password: "{{ remote_pulp_password }}" |
| 95 | + name: "{{ repository_name }}_latest" |
| 96 | + base_path: "{{ pulp_base_path }}/latest" |
| 97 | + publication: "{{ publication_details.publication.pulp_href }}" |
| 98 | + content_guard: development |
| 99 | + state: present |
| 100 | + register: latest_distribution_details |
| 101 | + until: latest_distribution_details is success |
| 102 | + retries: 3 |
| 103 | + delay: 5 |
| 104 | + |
| 105 | + - name: Create distribution for given version |
| 106 | + pulp.squeezer.file_distribution: |
| 107 | + pulp_url: "{{ remote_pulp_url }}" |
| 108 | + username: "{{ remote_pulp_username }}" |
| 109 | + password: "{{ remote_pulp_password }}" |
| 110 | + name: "{{ repository_name }}_{{ artifact_tag }}" |
| 111 | + base_path: "{{ pulp_base_path }}/{{ artifact_tag }}" |
| 112 | + publication: "{{ publication_details.publication.pulp_href }}" |
| 113 | + content_guard: development |
| 114 | + state: present |
| 115 | + when: latest_distribution_details.changed |
| 116 | + register: distribution_result |
| 117 | + until: distribution_result is success |
| 118 | + retries: 3 |
| 119 | + delay: 5 |
| 120 | + |
| 121 | + - name: Update new artifacts file with versioned path |
| 122 | + lineinfile: |
| 123 | + path: /tmp/updated_artifacts.txt |
| 124 | + line: "{{ remote_pulp_url }}/pulp/content/{{ pulp_base_path }}/\ |
| 125 | + {{ artifact_tag }}/{{ found_files.files[0].path | basename }}" |
| 126 | + create: true |
| 127 | + |
| 128 | + - name: Update new artifacts file with latest path |
| 129 | + lineinfile: |
| 130 | + path: /tmp/updated_artifacts.txt |
| 131 | + line: "{{ remote_pulp_url }}/pulp/content/{{ pulp_base_path }}/\ |
| 132 | + latest/{{ found_files.files[0].path | basename }}" |
| 133 | + when: latest_distribution_details.changed |
| 134 | + |
| 135 | + - name: Print versioned path |
| 136 | + debug: |
| 137 | + msg: "New versioned path: {{ remote_pulp_url }}/pulp/content/{{ pulp_base_path }}/\ |
| 138 | + {{ artifact_tag }}/{{ found_files.files[0].path | basename }}" |
| 139 | + when: latest_distribution_details.changed |
| 140 | + |
| 141 | + - name: Print latest path |
| 142 | + debug: |
| 143 | + msg: "New latest path: {{ remote_pulp_url }}/pulp/content/{{ pulp_base_path }}/\ |
| 144 | + latest/{{ found_files.files[0].path | basename }}" |
| 145 | + when: latest_distribution_details.changed |
| 146 | + |
| 147 | + - name: Print version tag |
| 148 | + debug: |
| 149 | + msg: "New tag: {{ artifact_tag }}" |
| 150 | + when: latest_distribution_details.changed |
0 commit comments