|
| 1 | +--- |
| 2 | + |
| 3 | +- name: Initialise facts |
| 4 | + set_fact: |
| 5 | + new_groups: [] |
| 6 | + current_groups: [] |
| 7 | + |
| 8 | +- name: Get RBAC content guard list |
| 9 | + uri: |
| 10 | + url: "{{ pulp_rbac_cg_url }}" |
| 11 | + user: "{{ pulp_admin_username }}" |
| 12 | + password: "{{ pulp_admin_password }}" |
| 13 | + method: GET |
| 14 | + status_code: 200 |
| 15 | + force_basic_auth: true |
| 16 | + no_log: true |
| 17 | + register: rbac_cg_list_result |
| 18 | + |
| 19 | +- name: Set fact new groups names |
| 20 | + set_fact: |
| 21 | + new_groups: "{{ (new_groups | default([])) + [item] }}" |
| 22 | + with_items: "{{ content_guard.download_groups | default([]) }}" |
| 23 | + |
| 24 | +- name: get current groups associated with content guard |
| 25 | + vars: |
| 26 | + url_query: "[?name=='{{ content_guard.name }}'].groups" |
| 27 | + set_fact: |
| 28 | + current_groups_full: "{{ rbac_cg_list_result.json.results | json_query(url_query) | first | default([]) }}" |
| 29 | + |
| 30 | +- name: Set fact current groups names |
| 31 | + set_fact: |
| 32 | + current_groups: "{{ (current_groups | default([])) + [item.name] }}" |
| 33 | + with_items: "{{ current_groups_full }}" |
| 34 | + |
| 35 | +- name: Add groups to RBAC content guards |
| 36 | + vars: |
| 37 | + url_query: "[?name=='{{ content_guard.name }}'].pulp_href" |
| 38 | + uri: |
| 39 | + url: "{{ pulp_url }}{{ rbac_cg_list_result.json.results | json_query(url_query) | first }}add_role/" |
| 40 | + user: "{{ pulp_admin_username }}" |
| 41 | + password: "{{ pulp_admin_password }}" |
| 42 | + force_basic_auth: true |
| 43 | + method: POST |
| 44 | + status_code: 201 |
| 45 | + body: |
| 46 | + groups: "{{ item }}" |
| 47 | + role: core.rbaccontentguard_downloader |
| 48 | + body_format: form-urlencoded |
| 49 | + loop: "{{ new_groups }}" |
| 50 | + loop_control: |
| 51 | + label: "{{ item }}" |
| 52 | + # no_log: true |
| 53 | + register: result |
| 54 | + when: item not in current_groups |
| 55 | + changed_when: result.status == 201 |
| 56 | + |
| 57 | +- name: Remove groups from RBAC content guards |
| 58 | + vars: |
| 59 | + url_query: "[?name=='{{ content_guard.name }}'].pulp_href" |
| 60 | + uri: |
| 61 | + url: "{{ pulp_url }}{{ rbac_cg_list_result.json.results | json_query(url_query) | first }}remove_role/" |
| 62 | + user: "{{ pulp_admin_username }}" |
| 63 | + password: "{{ pulp_admin_password }}" |
| 64 | + force_basic_auth: true |
| 65 | + method: POST |
| 66 | + status_code: 201 |
| 67 | + body: |
| 68 | + groups: "{{ item }}" |
| 69 | + role: core.rbaccontentguard_downloader |
| 70 | + body_format: form-urlencoded |
| 71 | + loop: "{{ current_groups }}" |
| 72 | + loop_control: |
| 73 | + label: "{{ item }}" |
| 74 | + no_log: true |
| 75 | + register: result |
| 76 | + when: item not in new_groups |
| 77 | + changed_when: result.status == 201 |
0 commit comments