main.yml 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. - name: Remove any CRBs that are not the default self-provisioners CRB.
  62. kubernetes.core.k8s:
  63. kubeconfig: tmp/kubeconfig-ocp4
  64. validate_certs: no
  65. api_version: rbac.authorization.k8s.io/v1
  66. kind: clusterrolebinding
  67. name: "{{ item }}"
  68. state: absent
  69. loop: "{{ sp_crbs | difference(['self-provisioners']) }}"
  70. - name: Ensure that the self-provisioners CRB lists only admin groups.
  71. kubernetes.core.k8s:
  72. kubeconfig: tmp/kubeconfig-ocp4
  73. validate_certs: no
  74. api_version: rbac.authorization.k8s.io/v1
  75. kind: clusterrolebinding
  76. name: self-provisioners
  77. resource_definition:
  78. roleRef:
  79. apiGroup: rbac.authorization.k8s.io
  80. kind: ClusterRole
  81. name: self-provisioner
  82. subjects:
  83. - apiGroup: rbac.authorization.k8s.io
  84. kind: Group
  85. name: admins
  86. - apiGroup: rbac.authorization.k8s.io
  87. kind: Group
  88. name: global-project-admins
  89. ...