install.yaml 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. ---
  2. - name: Create temp directory for doing work in on target
  3. command: mktemp -td openshift-cluster-monitoring-ansible-XXXXXX
  4. register: mktemp
  5. changed_when: False
  6. - set_fact:
  7. tempdir: "{{ mktemp.stdout }}"
  8. - name: Copy files to temp directory
  9. copy:
  10. src: "{{ item }}"
  11. dest: "{{ tempdir }}/{{ item }}"
  12. with_items:
  13. - cluster-monitoring-operator.yaml
  14. - name: Create templates subdirectory
  15. file:
  16. state: directory
  17. path: "{{ tempdir }}/{{ item }}"
  18. mode: 0755
  19. changed_when: False
  20. with_items:
  21. - templates
  22. - name: Copy admin client config
  23. command: >
  24. cp {{ openshift.common.config_base }}/master/admin.kubeconfig {{ mktemp.stdout }}/admin.kubeconfig
  25. changed_when: false
  26. - name: Add monitoring project
  27. oc_project:
  28. state: present
  29. name: openshift-monitoring
  30. description: Openshift Monitoring
  31. node_selector: ""
  32. - name: Label monitoring namespace
  33. oc_label:
  34. state: present
  35. kind: namespace
  36. name: openshift-monitoring
  37. labels:
  38. - key: openshift.io/cluster-monitoring
  39. value: "true"
  40. - when: os_sdn_network_plugin_name == 'redhat/openshift-ovs-multitenant'
  41. block:
  42. - name: Waiting for netnamespace openshift-monitoring to be ready
  43. oc_obj:
  44. kind: netnamespace
  45. name: openshift-monitoring
  46. state: list
  47. register: get_output
  48. until: not get_output.results.stderr is defined
  49. retries: 30
  50. delay: 1
  51. changed_when: false
  52. - name: Make openshift-monitoring project network global
  53. command: >
  54. {{ openshift_client_binary }} --config={{ mktemp.stdout }}/admin.kubeconfig adm pod-network make-projects-global openshift-monitoring
  55. - name: Apply the cluster monitoring operator ServiceAccount, Roles and Alertmanager config
  56. shell: >
  57. {{ openshift_client_binary }} process -n openshift-monitoring -f "{{ mktemp.stdout }}/{{ item }}"
  58. --param ALERTMANAGER_CONFIG="{{ openshift_cluster_monitoring_operator_alertmanager_config | b64encode }}"
  59. --param NAMESPACE="{{ openshift_cluster_monitoring_operator_namespace }}"
  60. --config={{ mktemp.stdout }}/admin.kubeconfig
  61. | {{ openshift_client_binary }} apply --config={{ mktemp.stdout }}/admin.kubeconfig -f -
  62. with_items:
  63. - cluster-monitoring-operator.yaml
  64. - name: Set cluster-monitoring-operator configmap template
  65. template:
  66. src: cluster-monitoring-operator-config.j2
  67. dest: "{{ tempdir }}/templates/cluster-monitoring-operator-config.yaml"
  68. changed_when: no
  69. - name: Set cluster-monitoring-operator configmap
  70. oc_obj:
  71. state: present
  72. name: "cluster-monitoring-config"
  73. namespace: "{{ openshift_cluster_monitoring_operator_namespace }}"
  74. kind: configmap
  75. files:
  76. - "{{ tempdir }}/templates/cluster-monitoring-operator-config.yaml"
  77. delete_after: true
  78. - name: Set cluster-monitoring-operator template
  79. template:
  80. src: cluster-monitoring-operator-deployment.j2
  81. dest: "{{ tempdir }}/templates/cluster-monitoring-operator-deployment.yaml"
  82. vars:
  83. namespace: "{{ openshift_cluster_monitoring_operator_namespace }}"
  84. - name: Set cluster-monitoring-operator template
  85. oc_obj:
  86. state: present
  87. name: "cluster-monitoring-operator"
  88. namespace: "{{ openshift_cluster_monitoring_operator_namespace }}"
  89. kind: deployment
  90. files:
  91. - "{{ tempdir }}/templates/cluster-monitoring-operator-deployment.yaml"
  92. delete_after: true
  93. - name: Wait for the ServiceMonitor CRD to be created
  94. command: "{{ openshift_client_binary }} get crd servicemonitors.monitoring.coreos.com -n openshift-monitoring --config={{ mktemp.stdout }}/admin.kubeconfig"
  95. register: crd
  96. until: crd.rc == 0
  97. delay: 30
  98. retries: 30
  99. - name: Delete temp directory
  100. file:
  101. name: "{{ mktemp.stdout }}"
  102. state: absent
  103. changed_when: False