|
| 1 | +--- |
| 2 | + |
| 3 | +- name: Get RBAC content guard list |
| 4 | + uri: |
| 5 | + url: "{{ pulp_rbac_cg_url }}" |
| 6 | + user: "{{ pulp_username }}" |
| 7 | + password: "{{ pulp_password }}" |
| 8 | + method: GET |
| 9 | + status_code: 200 |
| 10 | + force_basic_auth: true |
| 11 | + register: rbac_cg_list_result |
| 12 | + |
| 13 | +- name: Initialise remove_rbac_cg |
| 14 | + set_fact: |
| 15 | + remove_rbac_cg: [] |
| 16 | + |
| 17 | +- name: Set fact remove_rbac_cg |
| 18 | + set_fact: |
| 19 | + remove_rbac_cg: "{{ (remove_rbac_cg | default([])) + [item.name] }}" |
| 20 | + when: item.state is defined and item.state == 'absent' |
| 21 | + with_items: "{{ pulp_content_guard_rbac }}" |
| 22 | + |
| 23 | +- name: Create RBAC content guards |
| 24 | + vars: |
| 25 | + rbaccgnames: "{{ rbac_cg_list_result.json.results | map(attribute='name') | list }}" |
| 26 | + uri: |
| 27 | + url: "{{ pulp_rbac_cg_url }}" |
| 28 | + user: "{{ pulp_username }}" |
| 29 | + password: "{{ pulp_password }}" |
| 30 | + force_basic_auth: true |
| 31 | + method: POST |
| 32 | + status_code: 201 |
| 33 | + body: |
| 34 | + name: "{{ item.name }}" |
| 35 | + description: "{{ item.description | default(None) }}" |
| 36 | + body_format: form-urlencoded |
| 37 | + loop: "{{ pulp_content_guard_rbac }}" |
| 38 | + register: result |
| 39 | + when: |
| 40 | + - item.name not in rbaccgnames |
| 41 | + - item.state is not defined or item.state != 'absent' |
| 42 | + changed_when: result.status == 201 |
| 43 | + |
| 44 | +- name: Update existing rbac content guards |
| 45 | + vars: |
| 46 | + rbaccgnames: "{{ rbac_cg_list_result.json.results | map(attribute='name') | list }}" |
| 47 | + url_query: "[?name=='{{ item.name }}'].pulp_href" |
| 48 | + uri: |
| 49 | + url: "{{ pulp_url }}{{ rbac_cg_list_result.json.results | json_query(url_query) | first }}" |
| 50 | + user: "{{ pulp_username }}" |
| 51 | + password: "{{ pulp_password }}" |
| 52 | + force_basic_auth: true |
| 53 | + method: PATCH |
| 54 | + body: |
| 55 | + name: "{{ item.name }}" |
| 56 | + description: "{{ item.description | default(None) }}" |
| 57 | + body_format: form-urlencoded |
| 58 | + loop: "{{ pulp_content_guard_rbac }}" |
| 59 | + register: result |
| 60 | + when: |
| 61 | + - item.name in rbaccgnames |
| 62 | + - item.state is not defined or item.state != 'absent' |
| 63 | + changed_when: |
| 64 | + # The pulp API currently does not report when a change is made, so we must |
| 65 | + # manually check |
| 66 | + - result.json not in rbac_cg_list_result.json.results |
| 67 | + - result.status == 200 |
| 68 | + |
| 69 | +- name: Add or remove group roles from content guard |
| 70 | + include_tasks: add_or_remove_group_roles.yml |
| 71 | + loop: "{{ pulp_content_guard_rbac | default([], true) }}" |
| 72 | + loop_control: |
| 73 | + loop_var: content_guard |
| 74 | + when: not (content_guard.state is defined and content_guard.state == 'absent') |
| 75 | + |
| 76 | +- name: Initialise hrefs |
| 77 | + set_fact: |
| 78 | + hrefs: [] |
| 79 | + |
| 80 | +- name: Set fact hrefs |
| 81 | + set_fact: |
| 82 | + hrefs: "{{ (hrefs | default([])) + [item.pulp_href] }}" |
| 83 | + when: item.name in (remove_rbac_cg | default([])) |
| 84 | + with_items: "{{ rbac_cg_list_result.json.results }}" |
| 85 | + |
| 86 | +- name: Delete RBAC content guards |
| 87 | + uri: |
| 88 | + url: "{{ pulp_url }}{{ item }}" |
| 89 | + user: "{{ pulp_username }}" |
| 90 | + password: "{{ pulp_password }}" |
| 91 | + force_basic_auth: true |
| 92 | + method: DELETE |
| 93 | + status_code: 204 |
| 94 | + body_format: form-urlencoded |
| 95 | + loop: "{{ hrefs }}" |
| 96 | + register: result |
| 97 | + changed_when: result.status == 204 |
0 commit comments