Skip to content

Commit 0994beb

Browse files
authored
Merge pull request #27 from stackhpc/django-users
Add pulp_django_user role
2 parents 18aa268 + 4bfd4f3 commit 0994beb

File tree

4 files changed

+89
-0
lines changed

4 files changed

+89
-0
lines changed

roles/pulp_django_user/README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
pulp_django_user
2+
================
3+
4+
This role creates Django users using the Django admin site.
5+
6+
Role variables
7+
--------------
8+
9+
* `pulp_url`: URL of Pulp server. Default is `https://localhost:8080`
10+
* `pulp_admin_username`: Username used to access Pulp server. Default is `admin`
11+
* `pulp_admin_password`: Password used to access Pulp server. Default is unset
12+
* `pulp_validate_certs`: Whether to validate Pulp server certificate. Default is `true`
13+
* `pulp_django_users`: List of Django users to create. Default is an empty list.
14+
15+
Example playbook
16+
----------------
17+
18+
```
19+
---
20+
- name: Create Pulp Django users
21+
gather_facts: True
22+
hosts: localhost
23+
roles:
24+
- role: stackhpc.pulp.pulp_django_user
25+
pulp_url: https://pulp.example.com
26+
pulp_admin_username: admin
27+
pulp_admin_password: "{{ secrets_pulp_admin_password }}"
28+
pulp_django_users:
29+
- username: test-user
30+
password: correct horse battery staple
31+
```
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
pulp_url: https://localhost:8080
3+
pulp_admin_username: admin
4+
pulp_admin_password:
5+
pulp_validate_certs: true
6+
7+
pulp_django_users: []
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
# Interacting with Django requires us to use cookies for CSRF and login.
3+
# It also requires the use of a Referer header.
4+
5+
- name: Get a CSRF token
6+
uri:
7+
url: "{{ pulp_login_url }}"
8+
method: GET
9+
headers:
10+
Referer: "{{ pulp_login_url }}"
11+
validate_certs: "{{ pulp_validate_certs | bool }}"
12+
register: result_csrf
13+
14+
- name: Login
15+
uri:
16+
url: "{{ pulp_login_url }}"
17+
method: POST
18+
headers:
19+
Referer: "{{ pulp_login_url }}"
20+
Cookie: "{{ result_csrf.cookies_string }}"
21+
body:
22+
csrfmiddlewaretoken: "{{ result_csrf.cookies.csrftoken }}"
23+
username: "{{ pulp_admin_username }}"
24+
password: "{{ pulp_admin_password }}"
25+
body_format: form-urlencoded
26+
follow_redirects: all
27+
validate_certs: "{{ pulp_validate_certs | bool }}"
28+
register: result_login
29+
30+
# This returns 200 even if the user exists.
31+
- name: Create a user
32+
uri:
33+
url: "{{ pulp_add_user_url }}"
34+
method: POST
35+
headers:
36+
Referer: "{{ pulp_login_url }}"
37+
Cookie: "{{ result_login.cookies_string }}"
38+
body:
39+
csrfmiddlewaretoken: "{{ result_login.cookies.csrftoken }}"
40+
username: "{{ item.username }}"
41+
password1: "{{ item.password }}"
42+
password2: "{{ item.password }}"
43+
body_format: form-urlencoded
44+
follow_redirects: all
45+
validate_certs: "{{ pulp_validate_certs | bool }}"
46+
loop: "{{ pulp_django_users }}"
47+
loop_control:
48+
label: "{{ item.username }}"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
pulp_login_url: "{{ pulp_url }}/admin/login/?next=/admin/"
3+
pulp_add_user_url: "{{ pulp_url }}/admin/auth/user/add/"

0 commit comments

Comments
 (0)