main.yml 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. ---
  2. # Creates all ING-related ClusterRoles in the target cluster.
  3. # Ensures that corresponding OpenShift groups exist.
  4. # Only adds self-provisioner role to admin groups.
  5. - name: Make sure the cluster roles are there
  6. kubernetes.core.k8s:
  7. kubeconfig: tmp/kubeconfig-ocp4
  8. validate_certs: no
  9. api_version: rbac.authorization.k8s.io/v1
  10. kind: clusterrole
  11. name: "{{ item }}"
  12. src: "files/{{ item }}.yaml"
  13. loop: "{{ create_cluster_roles }}"
  14. - name: Ensure that corresponding cluster groups also exist
  15. kubernetes.core.k8s:
  16. kubeconfig: tmp/kubeconfig-ocp4
  17. validate_certs: no
  18. api_version: user.openshift.io/v1
  19. kind: group
  20. name: "{{ item | ansible.builtin.regex_replace('ichp', 'global') }}s"
  21. loop: "{{ create_cluster_roles }}"
  22. - name: Ensure that global groups have roles assigned to them.
  23. kubernetes.core.k8s:
  24. kubeconfig: tmp/kubeconfig-ocp4
  25. validate_certs: no
  26. api_version: rbac.authorization.k8s.io/v1
  27. kind: clusterrolebinding
  28. name: "{{ item }}s"
  29. resource_definition:
  30. roleRef:
  31. apiGroup: rbac.authorization.k8s.io
  32. kind: ClusterRole
  33. name: "{{ item }}"
  34. subjects:
  35. - kind: Group
  36. name: "{{ item | ansible.builtin.regex_replace('ichp', 'global') }}s"
  37. loop: "{{ create_cluster_roles }}"
  38. - name: Get all CRBs.
  39. kubernetes.core.k8s_info:
  40. kubeconfig: tmp/kubeconfig-ocp4
  41. validate_certs: no
  42. api_version: rbac.authorization.k8s.io/v1
  43. kind: clusterrolebinding
  44. register: all_crbs
  45. - name: Weed out CRBs that assign a self-provisioner CR.
  46. ansible.builtin.set_fact:
  47. sp_crbs: "{{ all_crbs | ansible.builtin.json_query('resources[?roleRef.name==`self-provisioner`].metadata.name') }}"
  48. - name: Warn if more than one role assigns self-provisioner.
  49. ansible.builtin.pause:
  50. prompt: |
  51. **************************************************************************
  52. * WARNING: More than one ClusterRoleBinding assigns the self-provisioner *
  53. * role to users. This role will fix the default one and remove *
  54. * any others. *
  55. * *
  56. * Interrupt execution by pressing Ctrl-C if this is not OK. *
  57. **************************************************************************
  58. seconds: 5
  59. when:
  60. - (sp_crbs | length > 1) or (sp_crbs is not contains("self-provisioners"))
  61. # Looks like we have to remove all of them and recreate self-provisioner.
  62. - name: Remove any CRBs that are not the default self-provisioners CRB.
  63. kubernetes.core.k8s:
  64. kubeconfig: tmp/kubeconfig-ocp4
  65. validate_certs: no
  66. api_version: rbac.authorization.k8s.io/v1
  67. kind: clusterrolebinding
  68. name: "{{ item }}"
  69. state: absent
  70. loop: "{{ sp_crbs }}"
  71. # "{{ sp_crbs | difference(['self-provisioners']) }}"
  72. - name: Ensure that the self-provisioners CRB lists only admin groups.
  73. kubernetes.core.k8s:
  74. kubeconfig: tmp/kubeconfig-ocp4
  75. validate_certs: no
  76. api_version: rbac.authorization.k8s.io/v1
  77. kind: clusterrolebinding
  78. name: self-provisioners
  79. resource_definition:
  80. roleRef:
  81. apiGroup: rbac.authorization.k8s.io
  82. kind: ClusterRole
  83. name: self-provisioner
  84. subjects:
  85. - apiGroup: rbac.authorization.k8s.io
  86. kind: Group
  87. name: admins
  88. - apiGroup: rbac.authorization.k8s.io
  89. kind: Group
  90. name: global-project-admins
  91. ...