main.yml 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. ---
  2. # Adds ichp-project-admin role to project requester and taints the project.
  3. #
  4. - name: Check if the project exists.
  5. kubernetes.core.k8s_info:
  6. kubeconfig: tmp/kubeconfig-ocp4
  7. validate_certs: no
  8. api_version: v1
  9. kind: namespace
  10. name: "{{ role.name }}"
  11. register: project_state
  12. - name: Some basic assertions.
  13. ansible.builtin.assert:
  14. that:
  15. - project_state.resources is defined
  16. - project_state.resources | length == 1
  17. success_msg: "OK, project found."
  18. fail_msg: "FATAL: project \"{{ role.name }}\" not found."
  19. - name: Verify that this is an ICHP project.
  20. ansible.builtin.assert:
  21. that:
  22. - project_state.resources[0].metadata.labels.keys() is contains('ichp.ing.net/generated')
  23. success_msg: "OK, project is an ICHP project."
  24. fail_msg: "FATAL: project is NOT an ICHP project."
  25. - name: Check if we can see who the requester is.
  26. ansible.builtin.assert:
  27. that:
  28. - project_state.resources[0].metadata.annotations['openshift.io/requester'] is defined
  29. success_msg: "OK, found project requester."
  30. fail_msg: "FATAL: can not find out who requested the project."
  31. - name: Remember the requester as a fact.
  32. ansible.builtin.set_fact:
  33. requester: "{{ project_state.resources[0].metadata.annotations['openshift.io/requester'] }}"
  34. - name: Verify that this is an actual user.
  35. kubernetes.core.k8s_info:
  36. kubeconfig: tmp/kubeconfig-ocp4
  37. validate_certs: no
  38. api_version: user.openshift.io/v1
  39. kind: user
  40. name: "{{ requester }}"
  41. register: requester_user
  42. - name: Assertions about the user.
  43. ansible.builtin.assert:
  44. that:
  45. - requester_user.resources is defined
  46. - requester_user.resources | length == 1
  47. success_msg: "OK, \"{{ requester }}\" is an existing user."
  48. fail_msg: "FATAL: \"{{ requester }}\" user does not exist."
  49. - name: Annotate and label the project as tainted.
  50. kubernetes.core.k8s:
  51. kubeconfig: tmp/kubeconfig-ocp4
  52. validate_certs: no
  53. api_version: v1
  54. kind: namespace
  55. name: "{{ role.name }}"
  56. state: patched
  57. resource_definition:
  58. metadata:
  59. annotations:
  60. ichp.ing.net/tainted: "true"
  61. labels:
  62. ichp.ing.net/tainted: "true"
  63. - name: Create an admin rolebinding.
  64. kubernetes.core.k8s:
  65. kubeconfig: tmp/kubeconfig-ocp4
  66. validate_certs: no
  67. api_version: rbac.authorization.k8s.io/v1
  68. kind: rolebinding
  69. name: ichp-break-glass-rb
  70. namespace: "{{ role.name }}"
  71. resource_definition:
  72. roleRef:
  73. apiGroup: rbac.authorization.k8s.io
  74. kind: ClusterRole
  75. name: ichp-project-admin
  76. subjects:
  77. apiGroup: rbac.authorization.k8s.io
  78. kind: User
  79. name: "{{ requester }}"
  80. ...