main.yml 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. ---
  2. - name: Create grafana namespace
  3. oc_project:
  4. state: present
  5. name: grafana
  6. - name: Configure Grafana Permissions
  7. include_tasks: tasks/gf-permissions.yml
  8. when: gf_oauth | default(false) | bool == true
  9. # TODO: we should grab this yaml file from openshift/origin
  10. - name: Templatize grafana yaml
  11. template: src=grafana-ocp.yaml dest=/tmp/grafana-ocp.yaml
  12. register:
  13. cl_file: /tmp/grafana-ocp.yaml
  14. when: gf_oauth | default(false) | bool == false
  15. # TODO: we should grab this yaml file from openshift/origin
  16. - name: Templatize grafana yaml
  17. template: src=grafana-ocp-oauth.yaml dest=/tmp/grafana-ocp-oauth.yaml
  18. register:
  19. cl_file: /tmp/grafana-ocp-oauth.yaml
  20. when: gf_oauth | default(false) | bool == true
  21. - name: Process the grafana file
  22. oc_process:
  23. namespace: grafana
  24. template_name: "{{ cl_file }}"
  25. create: True
  26. when: gf_oauth | default(false) | bool == true
  27. - name: Wait to grafana be running
  28. command: oc rollout status deployment/grafana-ocp
  29. - name: oc adm policy add-role-to-user view -z grafana-ocp -n {{ gf_prometheus_namespace }}
  30. oc_adm_policy_user:
  31. user: grafana-ocp
  32. resource_kind: cluster-role
  33. resource_name: view
  34. state: present
  35. role_namespace: "{{ gf_prometheus_namespace }}"
  36. - name: Get grafana route
  37. oc_obj:
  38. kind: route
  39. name: grafana
  40. namespace: grafana
  41. register: route
  42. - name: Get prometheus route
  43. oc_obj:
  44. kind: route
  45. name: prometheus
  46. namespace: "{{ gf_prometheus_namespace }}"
  47. register: route
  48. - name: Get the prometheus SA
  49. oc_serviceaccount_secret:
  50. state: list
  51. service_account: prometheus
  52. namespace: "{{ gf_prometheus_namespace }}"
  53. register: sa
  54. - name: Get the management SA bearer token
  55. set_fact:
  56. management_token: "{{ sa.results | oo_filter_sa_secrets }}"
  57. - name: Ensure the SA bearer token value is read
  58. oc_secret:
  59. state: list
  60. name: "{{ management_token }}"
  61. namespace: "{{ gf_prometheus_namespace }}"
  62. no_log: True
  63. register: sa_secret
  64. - name: Get the SA bearer token for prometheus
  65. set_fact:
  66. token: "{{ sa_secret.results.encoded.token }}"
  67. - name: Convert to json
  68. var:
  69. ds_json: "{{ gf_body_tmp }} | to_json }}"
  70. - name: Set protocol type
  71. var:
  72. protocol: "{{ 'https' if {{ gf_oauth }} == true else 'http' }}"
  73. - name: Add gf datasrouce
  74. uri:
  75. url: "{{ protocol }}://{{ route }}/api/datasources"
  76. user: admin
  77. password: admin
  78. method: POST
  79. body: "{{ ds_json | regex_replace('grafana_name', {{ gf_datasource_name }}) | regex_replace('prometheus_url', 'https://'{{ prometheus }} ) | regex_replace('satoken', {{ token }}) }}"
  80. headers:
  81. Content-Type: "Content-Type: application/json"
  82. register: add_ds
  83. - name: Regex setup ds name
  84. replace:
  85. path: "{{ lookup('file', 'openshift-cluster-monitoring.json') }}"
  86. regexp: '${DS_PR}'
  87. replace: '{{ gf_datasource_name }}'
  88. backup: yes
  89. - name: Add new dashboard
  90. uri:
  91. url: "{{ protocol }}://{{ route }}/api/dashboards/db"
  92. user: admin
  93. password: admin
  94. method: POST
  95. body: "{{ lookup('file', 'openshift-cluster-monitoring.json') }}"
  96. headers:
  97. Content-Type: "Content-Type: application/json"
  98. register: add_ds
  99. - name: Regex json tear down
  100. replace:
  101. path: "{{ lookup('file', 'openshift-cluster-monitoring.json') }}"
  102. regexp: '${DS_PR}'
  103. replace: '{{ gf_datasource_name }}'
  104. backup: yes