deploy_logging.yaml 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. ---
  2. - debug: msg="WARNING target_registry is deprecated, use openshift_hosted_logging_image_prefix instead"
  3. when: target_registry is defined and target_registry
  4. - fail: msg="This role requires the following vars to be defined. openshift_hosted_logging_master_public_url, openshift_hosted_logging_hostname, openshift_hosted_logging_elasticsearch_cluster_size"
  5. when: "openshift_hosted_logging_hostname is not defined or
  6. openshift_hosted_logging_elasticsearch_cluster_size is not defined or
  7. openshift_hosted_logging_master_public_url is not defined"
  8. - name: Create temp directory for kubeconfig
  9. command: mktemp -d /tmp/openshift-ansible-XXXXXX
  10. register: mktemp
  11. changed_when: False
  12. - name: Copy the admin client config(s)
  13. command: >
  14. cp {{ openshift_master_config_dir }}/admin.kubeconfig {{ mktemp.stdout }}/admin.kubeconfig
  15. changed_when: False
  16. - name: "Check for logging project already exists"
  17. command: >
  18. {{ openshift.common.client_binary }} --config={{ mktemp.stdout }}/admin.kubeconfig get project logging -o jsonpath='{.metadata.name}'
  19. register: logging_project_result
  20. ignore_errors: True
  21. - name: "Create logging project"
  22. command: >
  23. {{ openshift.common.client_binary }} adm --config={{ mktemp.stdout }}/admin.kubeconfig new-project logging
  24. when: logging_project_result.stdout == ""
  25. - name: "Changing projects"
  26. command: >
  27. {{ openshift.common.client_binary }} --config={{ mktemp.stdout }}/admin.kubeconfig project logging
  28. - name: "Creating logging deployer secret"
  29. command: >
  30. {{ openshift.common.client_binary }} --config={{ mktemp.stdout }}/admin.kubeconfig secrets new logging-deployer {{ openshift_hosted_logging_secret_vars | default('nothing=/dev/null') }}
  31. register: secret_output
  32. failed_when: "secret_output.rc == 1 and 'exists' not in secret_output.stderr"
  33. - name: "Create templates for logging accounts and the deployer"
  34. command: >
  35. {{ openshift.common.client_binary }} create
  36. -f {{ hosted_base }}/logging-deployer.yaml
  37. --config={{ mktemp.stdout }}/admin.kubeconfig
  38. -n logging
  39. register: logging_import_template
  40. failed_when: "'already exists' not in logging_import_template.stderr and logging_import_template.rc != 0"
  41. changed_when: "'created' in logging_import_template.stdout"
  42. - name: "Process the logging accounts template"
  43. shell: "{{ openshift.common.client_binary }} --config={{ mktemp.stdout }}/admin.kubeconfig process logging-deployer-account-template | {{ openshift.common.client_binary }} --config={{ mktemp.stdout }}/admin.kubeconfig create -f -"
  44. register: process_deployer_accounts
  45. failed_when: process_deployer_accounts.rc == 1 and 'already exists' not in process_deployer_accounts.stderr
  46. - name: "Set permissions for logging-deployer service account"
  47. command: >
  48. {{ openshift.common.client_binary }} adm --config={{ mktemp.stdout }}/admin.kubeconfig policy add-cluster-role-to-user oauth-editor system:serviceaccount:logging:logging-deployer
  49. register: permiss_output
  50. failed_when: "permiss_output.rc == 1 and 'exists' not in permiss_output.stderr"
  51. - name: "Set permissions for fluentd"
  52. command: >
  53. {{ openshift.common.client_binary }} adm policy add-scc-to-user privileged system:serviceaccount:logging:aggregated-logging-fluentd
  54. register: fluentd_output
  55. failed_when: "fluentd_output.rc == 1 and 'exists' not in fluentd_output.stderr"
  56. - name: "Set additional permissions for fluentd"
  57. command: >
  58. {{ openshift.common.client_binary }} adm policy add-cluster-role-to-user cluster-reader system:serviceaccount:logging:aggregated-logging-fluentd
  59. register: fluentd2_output
  60. failed_when: "fluentd2_output.rc == 1 and 'exists' not in fluentd2_output.stderr"
  61. - name: "Create ConfigMap for deployer parameters"
  62. command: >
  63. {{ openshift.common.client_binary}} --config={{ mktemp.stdout }}/admin.kubeconfig create configmap logging-deployer {{ deployer_cmap_params }}
  64. register: deployer_configmap_output
  65. failed_when: "deployer_configmap_output.rc == 1 and 'exists' not in deployer_configmap_output.stderr"
  66. - name: "Process the deployer template"
  67. shell: "{{ openshift.common.client_binary }} --config={{ mktemp.stdout }}/admin.kubeconfig new-app logging-deployer-template {{ oc_new_app_values }}"
  68. register: process_deployer
  69. failed_when: process_deployer.rc == 1 and 'already exists' not in process_deployer.stderr
  70. - name: "Wait for image pull and deployer pod"
  71. shell: "{{ openshift.common.client_binary }} --config={{ mktemp.stdout }}/admin.kubeconfig get pods | grep logging-deployer.*Completed"
  72. register: result
  73. until: result.rc == 0
  74. retries: 20
  75. delay: 15
  76. - name: "Process imagestream template"
  77. shell: "{{ openshift.common.client_binary }} --config={{ mktemp.stdout }}/admin.kubeconfig new-app logging-imagestream-template {{ oc_new_app_values }}"
  78. when: tr_or_ohlip is defined and insecure_registry is defined and insecure_registry
  79. register: process_is
  80. failed_when: process_is.rc == 1 and 'already exists' not in process_is.stderr
  81. - name: "Set insecured registry"
  82. command: "{{ openshift.common.client_binary }} --config={{ mktemp.stdout }}/admin.kubeconfig annotate is --all openshift.io/image.insecureRepository=true --overwrite"
  83. when: tr_or_ohlip is defined and insecure_registry is defined and insecure_registry
  84. - name: "Wait for imagestreams to become available"
  85. shell: "{{ openshift.common.client_binary }} --config={{ mktemp.stdout }}/admin.kubeconfig get is | grep logging-fluentd"
  86. when: tr_or_ohlip is defined and insecure_registry is defined and insecure_registry
  87. register: result
  88. until: result.rc == 0
  89. failed_when: result.rc == 1 and 'not found' not in result.stderr
  90. retries: 20
  91. delay: 5
  92. - name: "Wait for component pods to be running"
  93. shell: "{{ openshift.common.client_binary }} --config={{ mktemp.stdout }}/admin.kubeconfig get pods -l component={{ item }} | grep Running"
  94. with_items:
  95. - es
  96. - kibana
  97. - curator
  98. register: result
  99. until: result.rc == 0
  100. failed_when: result.rc == 1 or 'Error' in result.stderr
  101. retries: 20
  102. delay: 15
  103. - name: "Wait for ops component pods to be running"
  104. shell: "{{ openshift.common.client_binary }} --config={{ mktemp.stdout }}/admin.kubeconfig get pods -l component={{ item }} | grep Running"
  105. with_items:
  106. - es-ops
  107. - kibana-ops
  108. - curator-ops
  109. when: openshift_hosted_logging_enable_ops_cluster is defined and openshift_hosted_logging_enable_ops_cluster
  110. register: result
  111. until: result.rc == 0
  112. failed_when: result.rc == 1 or 'Error' in result.stderr
  113. retries: 20
  114. delay: 15
  115. - name: "Wait for fluentd DaemonSet to exist"
  116. shell: "{{ openshift.common.client_binary }} --config={{ mktemp.stdout }}/admin.kubeconfig get daemonset logging-fluentd"
  117. register: result
  118. until: result.rc == 0
  119. failed_when: result.rc == 1 or 'Error' in result.stderr
  120. retries: 20
  121. delay: 5
  122. - name: "Deploy fluentd by labeling the node"
  123. shell: "{{ openshift.common.client_binary }} --config={{ mktemp.stdout }}/admin.kubeconfig label node --overwrite=true {{ '-l' ~ openshift_hosted_logging_fluentd_nodeselector if openshift_hosted_logging_fluentd_nodeselector is defined else '--all' }} {{ openshift_hosted_logging_fluentd_nodeselector_label if openshift_hosted_logging_fluentd_nodeselector_label is defined else 'logging-infra-fluentd=true' }}"
  124. - name: "Wait for fluentd to be running"
  125. shell: "{{ openshift.common.client_binary }} --config={{ mktemp.stdout }}/admin.kubeconfig get pods -l component=fluentd | grep Running"
  126. register: result
  127. until: result.rc == 0
  128. failed_when: result.rc == 1 or 'Error' in result.stderr
  129. retries: 20
  130. delay: 15
  131. - debug:
  132. msg: "Logging components deployed. Note persistent volume for elasticsearch must be setup manually"
  133. - name: Delete temp directory
  134. file:
  135. name: "{{ mktemp.stdout }}"
  136. state: absent
  137. changed_when: False