Skip to content

Commit 707bd1e

Browse files
committed
Moving rbac to pulp_content_guard
1 parent 1bba733 commit 707bd1e

File tree

10 files changed

+142
-139
lines changed

10 files changed

+142
-139
lines changed

roles/pulp_content_guard/README.md

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,16 @@ Role variables
1010
* `pulp_username`: Username used to access Pulp server. Default is `admin`
1111
* `pulp_password`: Password used to access Pulp server. Default is unset
1212
* `pulp_validate_certs`: Whether to validate Pulp server certificate. Default is `true`
13-
* `pulp_content_guard_x509_cert_guards`: List of x509 cert guards. Each item is
14-
a dict with the following keys: `name`, `description`, `ca_certificate`,
15-
`state`.
13+
* `pulp_content_guard_x509_cert_guards`: List of x509 cert guards to create/update/delete. Each item is
14+
a dict containing:
15+
* `name` (Required)
16+
* `description`
17+
* `ca_certificate`
18+
* `state` (default is `present`. Setting this value to `absent` will delete the content guard if it exists)
19+
* `pulp_content_guard_rbac`: List of groups to create/update/delete. Default is an empty list. Each item is a dict containing:
20+
* `name` (Required)
21+
* `download_groups` (list of groups to to be added to this content guard with the download role)
22+
* `state` (default is `present`. Setting this value to `absent` will delete the content guard if it exists)
1623

1724

1825
Example playbook
@@ -25,7 +32,7 @@ Example playbook
2532
gather_facts: True
2633
hosts: all
2734
roles:
28-
- role: stackhpc.pulp.pulp_contentguard
35+
- role: stackhpc.pulp.pulp_content_guard
2936
pulp_username: admin
3037
pulp_password: "{{ secrets_pulp_admin_password }}"
3138
pulp_content_guard_x509_cert_guards:
@@ -36,4 +43,25 @@ Example playbook
3643
...
3744
-----END CERTIFICATE-----
3845
state: present
46+
47+
- role: stackhpc.pulp.pulp_content_guard
48+
pulp_url: http://localhost:8080
49+
pulp_username: admin
50+
pulp_password: "{{ secrets_pulp_admin_password }}"
51+
pulp_content_guard_rbac:
52+
- name: alex-test-rbac_cg-1
53+
description: test-description-edited
54+
download_groups:
55+
- alex-test-group-1
56+
- alex-test-group-2
57+
state: present
58+
- name: alex-test-rbac_cg-2
59+
description: test-description2-edited
60+
download_groups:
61+
- alex-test-group-2
62+
- name: alex-test-rbac_cg-3
63+
description: test-description3-edited
64+
download_groups:
65+
- alex-test-group-1
66+
state: absent
3967
```

roles/pulp_content_guard/defaults/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ pulp_password:
55
pulp_validate_certs: true
66

77
pulp_content_guard_x509_cert_guards: []
8+
pulp_content_guard_rbac: []

roles/pulp_content_guard/tasks/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@
1212
with_items: "{{ pulp_content_guard_x509_cert_guards }}"
1313
loop_control:
1414
label: "{{ item.name }}"
15+
16+
- name: Ensure RBAC cert guards exist
17+
include_tasks: rbac/rbac.yml

roles/pulp_content_guard_rbac/tasks/rbac_group/add_or_remove_groups.yml renamed to roles/pulp_content_guard/tasks/rbac/add_or_remove_groups.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
- name: Get RBAC content guard list
99
uri:
1010
url: "{{ pulp_rbac_cg_url }}"
11-
user: "{{ pulp_admin_username }}"
12-
password: "{{ pulp_admin_password }}"
11+
user: "{{ pulp_username }}"
12+
password: "{{ pulp_password }}"
1313
method: GET
1414
status_code: 200
1515
force_basic_auth: true
@@ -37,8 +37,8 @@
3737
url_query: "[?name=='{{ content_guard.name }}'].pulp_href"
3838
uri:
3939
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 }}"
40+
user: "{{ pulp_username }}"
41+
password: "{{ pulp_password }}"
4242
force_basic_auth: true
4343
method: POST
4444
status_code: 201
@@ -59,8 +59,8 @@
5959
url_query: "[?name=='{{ content_guard.name }}'].pulp_href"
6060
uri:
6161
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 }}"
62+
user: "{{ pulp_username }}"
63+
password: "{{ pulp_password }}"
6464
force_basic_auth: true
6565
method: POST
6666
status_code: 201
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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+
no_log: true
12+
register: rbac_cg_list_result
13+
14+
- name: Set fact remove_rbac_cg
15+
set_fact:
16+
remove_rbac_cg: "{{ (remove_rbac_cg | default([])) + [item.name] }}"
17+
when: item.state | default('present') == 'absent'
18+
with_items: "{{ pulp_content_guard_rbac }}"
19+
20+
- name: Create RBAC content guards
21+
vars:
22+
rbaccgnames: "{{ rbac_cg_list_result.json.results | map(attribute='name') | list }}"
23+
uri:
24+
url: "{{ pulp_rbac_cg_url }}"
25+
user: "{{ pulp_username }}"
26+
password: "{{ pulp_password }}"
27+
force_basic_auth: true
28+
method: POST
29+
status_code: 201
30+
body:
31+
name: "{{ item.name }}"
32+
description: "{{ item.description | default(omit) }}"
33+
body_format: form-urlencoded
34+
loop: "{{ pulp_content_guard_rbac | default([], true) }}"
35+
loop_control:
36+
label: "{{ item.name }}"
37+
# no_log: true
38+
register: result
39+
when:
40+
- item.name not in rbaccgnames
41+
- item.state | default('present') != '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(omit) }}"
57+
body_format: form-urlencoded
58+
loop: "{{ pulp_content_guard_rbac | default([], true) }}"
59+
# no_log: true
60+
register: result
61+
when:
62+
- item.name in rbaccgnames
63+
- item.state | default('present') != 'absent'
64+
changed_when:
65+
# The pulp API currently does not report when a change is made, so we must
66+
# manually check
67+
- result.json not in rbac_cg_list_result.json.results
68+
- result.status == 200
69+
70+
- name: Add or remove group(s) from content guard
71+
include_tasks: add_or_remove_groups.yml
72+
loop: "{{ pulp_content_guard_rbac | default([], true) }}"
73+
loop_control:
74+
loop_var: content_guard
75+
when: content_guard.state | default('present') != 'absent'
76+
77+
- name: Initialise hrefs
78+
set_fact:
79+
hrefs: []
80+
81+
- name: Set fact hrefs
82+
set_fact:
83+
hrefs: "{{ (hrefs | default([])) + [item.pulp_href] }}"
84+
when: item.name in (remove_rbac_cg | default([]))
85+
with_items: "{{ rbac_cg_list_result.json.results }}"
86+
87+
- name: Delete RBAC content guards
88+
uri:
89+
url: "{{ pulp_url }}{{ item }}"
90+
user: "{{ pulp_username }}"
91+
password: "{{ pulp_password }}"
92+
force_basic_auth: true
93+
method: DELETE
94+
status_code: 204
95+
body_format: form-urlencoded
96+
loop: "{{ hrefs | default([]) }}"
97+
no_log: true
98+
register: result
99+
changed_when: result.status == 204

roles/pulp_content_guard_rbac/README.md

Lines changed: 0 additions & 48 deletions
This file was deleted.

roles/pulp_content_guard_rbac/defaults/main.yml

Lines changed: 0 additions & 8 deletions
This file was deleted.

roles/pulp_content_guard_rbac/tasks/main.yml

Lines changed: 0 additions & 72 deletions
This file was deleted.

roles/pulp_user/defaults/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ pulp_admin_username: admin
44
pulp_admin_password:
55
pulp_validate_certs: true
66

7-
pulp_users: []
7+
pulp_users: []

0 commit comments

Comments
 (0)