stateful-start.yml 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. ---
  2. - name: Prepare for the strategies exercise
  3. hosts: workstation.lab.example.com
  4. gather_subset: min
  5. become: no
  6. vars:
  7. ge_nsp: deployments-stateful
  8. tasks:
  9. - name: Make sure kubeconfig is there on utility
  10. delegate_to: utility.lab.example.com
  11. file:
  12. path: /home/lab/{{ item }}/auth/kubeconfig
  13. state: file
  14. loop: "{{ clusters }}"
  15. - name: Create a temp dir
  16. file:
  17. path: tmp
  18. state: directory
  19. - name: Copy over the kubeconfig
  20. delegate_to: utility.lab.example.com
  21. fetch:
  22. src: /home/lab/{{ item }}/auth/kubeconfig
  23. dest: tmp/kubeconfig-{{ item }}
  24. flat: yes
  25. loop: "{{ clusters }}"
  26. - name: Check whether the namespace is already there
  27. k8s_info:
  28. kubeconfig: tmp/kubeconfig-ocp4
  29. validate_certs: no
  30. api_version: v1
  31. kind: namespace
  32. name: "{{ ge_nsp }}"
  33. register: ge_exists
  34. - name: Fail if the namespace exists
  35. fail:
  36. msg: "The exercise namespace already exists: {{ ge_nsp }}; please run strategy-finish.yml to clean up first and then re-run this playbook."
  37. when: ge_exists.resources | length > 0
  38. - name: Ensure there is a namespace for the exercise
  39. k8s:
  40. kubeconfig: tmp/kubeconfig-ocp4
  41. validate_certs: no
  42. api_version: v1
  43. kind: namespace
  44. name: "{{ ge_nsp }}"
  45. - name: Give developer admin role in the project
  46. k8s:
  47. kubeconfig: tmp/kubeconfig-ocp4
  48. validate_certs: no
  49. api_version: rbac.authorization.k8s.io/v1
  50. kind: rolebinding
  51. namespace: "{{ ge_nsp }}"
  52. name: dev-admin
  53. definition:
  54. roleRef:
  55. apiGroup: rbac.authorization.k8s.io
  56. kind: ClusterRole
  57. name: admin
  58. subjects:
  59. - apiGroup: rbac.authorization.k8s.io
  60. kind: User
  61. name: developer