main.yml 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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-admin
  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. - name: Create a debugger rolebinding.
  81. kubernetes.core.k8s:
  82. kubeconfig: tmp/kubeconfig-ocp4
  83. validate_certs: no
  84. api_version: rbac.authorization.k8s.io/v1
  85. kind: rolebinding
  86. name: ichp-break-glass-rb-debugger
  87. namespace: "{{ role.name }}"
  88. resource_definition:
  89. roleRef:
  90. apiGroup: rbac.authorization.k8s.io
  91. kind: ClusterRole
  92. name: ichp-project-debugger
  93. subjects:
  94. - apiGroup: rbac.authorization.k8s.io
  95. kind: User
  96. name: "{{ requester }}"
  97. ...