monitoring-start.yml 2.3 KB

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