summaryrefslogtreecommitdiffstats
path: root/roles/ands_openshift/tasks/users_resources.yml
blob: 722e1eb986e26cb533143e0ecb04e516d9437f8f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
---
- name: Configure cluster roles
  command: "oc adm policy add-cluster-role-to-user {{  item.key.split('/')[0] }} {{ item.value.replace(' ','').split(',') | join(' ') }}"
  with_dict: "{{ ands_openshift_roles }}"
  when: key_len == "1"
  vars:
    key_len: "{{ item.key.split('/') | length }}"

- name: Get project list
  command: "oc get projects -o json"
  changed_when: false
  register: results

- name: Find missing projects
  set_fact: new_projects="{{ ands_openshift_projects.keys() | difference (results.stdout | from_json | json_query('items[*].metadata.name')) }}"
  when: (results | succeeded)

- name: Create missing projects
  command: "oc adm new-project --description '{{ ands_openshift_projects[item] }}' {{ item }}"
  with_items: "{{ new_projects | default([]) }}"

- name: Allow projects to pull images from KaaS imagestreams
  command: "oc policy add-role-to-group system:image-puller system:serviceaccounts:{{ prj_item }} --namespace=kaas"
  with_items: "{{ ands_openshift_projects.keys() }}"
  when:
    prj_item != "kaas"
  loop_control: 
    loop_var: prj_item

- name: Configure per project roles
  command: "oc adm policy add-role-to-user -n {{  item.key.split('/')[0] }} {{ item.key.split('/')[1] }} {{ item.value.replace(' ','').split(',') | join(' ') }}"
  with_dict: "{{ ands_openshift_roles }}"
  when: key_len == "2"
  vars:
    key_len: "{{ item.key.split('/') | length }}"

- name: Get user list
  command: "oc get users -o json"
  changed_when: false
  register: results

- name: Find removed users
  set_fact: removed_users="{{ results.stdout | from_json | json_query('items[*].metadata.name') | difference(ands_openshift_users.keys()) }}"
  when: (results | succeeded)

- name: Remove user authentication
  command: "oc delete identity htpasswd_auth:{{ item }}"
  with_items: "{{ removed_users | default([]) }}"

- name: Remove users
  command: "oc delete user {{ item }}"
  with_items: "{{ removed_users | default([]) }}"