deploy_logging.yaml 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. ---
  2. - 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"
  3. when: "openshift_hosted_logging_hostname is not defined or
  4. openshift_hosted_logging_elasticsearch_cluster_size is not defined or
  5. openshift_hosted_logging_master_public_url is not defined"
  6. - name: Create temp directory for kubeconfig
  7. command: mktemp -d /tmp/openshift-ansible-XXXXXX
  8. register: mktemp
  9. changed_when: False
  10. - name: Copy the admin client config(s)
  11. command: >
  12. cp {{ openshift_master_config_dir }}/admin.kubeconfig {{ mktemp.stdout }}/admin.kubeconfig
  13. changed_when: False
  14. - name: Check for logging project already exists
  15. command: >
  16. {{ openshift.common.client_binary }} --config={{ mktemp.stdout }}/admin.kubeconfig get project logging -o jsonpath='{.metadata.name}'
  17. register: logging_project_result
  18. ignore_errors: True
  19. - name: "Create logging project"
  20. command: >
  21. {{ openshift.common.admin_binary }} --config={{ mktemp.stdout }}/admin.kubeconfig new-project logging
  22. when: logging_project_result.stdout == ""
  23. - name: "Changing projects"
  24. command: >
  25. {{ openshift.common.client_binary }} --config={{ mktemp.stdout }}/admin.kubeconfig project logging
  26. - name: "Creating logging deployer secret"
  27. command: >
  28. {{ openshift.common.client_binary }} --config={{ mktemp.stdout }}/admin.kubeconfig secrets new logging-deployer {{ openshift_hosted_logging_secret_vars | default('nothing=/dev/null') }}
  29. register: secret_output
  30. failed_when: "secret_output.rc == 1 and 'exists' not in secret_output.stderr"
  31. - name: "Copy serviceAccount file"
  32. copy:
  33. dest: /tmp/logging-deployer-sa.yaml
  34. src: "{{role_path}}/files/logging-deployer-sa.yaml"
  35. force: yes
  36. - name: "Create logging-deployer service account"
  37. command: >
  38. {{ openshift.common.client_binary }} --config={{ mktemp.stdout }}/admin.kubeconfig create -f /tmp/logging-deployer-sa.yaml
  39. register: deployer_output
  40. failed_when: "deployer_output.rc == 1 and 'exists' not in deployer_output.stderr"
  41. - name: "Set permissions for logging-deployer service account"
  42. command: >
  43. {{ openshift.common.client_binary }} --config={{ mktemp.stdout }}/admin.kubeconfig policy add-role-to-user edit system:serviceaccount:logging:logging-deployer
  44. register: permiss_output
  45. failed_when: "permiss_output.rc == 1 and 'exists' not in permiss_output.stderr"
  46. - name: "Set permissions for fluentd"
  47. command: >
  48. {{ openshift.common.admin_binary}} policy add-scc-to-user privileged system:serviceaccount:logging:aggregated-logging-fluentd
  49. register: fluentd_output
  50. failed_when: "fluentd_output.rc == 1 and 'exists' not in fluentd_output.stderr"
  51. - name: "Set additional permissions for fluentd"
  52. command: >
  53. {{ openshift.common.admin_binary}} policy add-cluster-role-to-user cluster-reader system:serviceaccount:logging:aggregated-logging-fluentd
  54. register: fluentd2_output
  55. failed_when: "fluentd2_output.rc == 1 and 'exists' not in fluentd2_output.stderr"
  56. - name: "Create deployer template"
  57. command: >
  58. {{ openshift.common.client_binary }} --config={{ mktemp.stdout }}/admin.kubeconfig create -f /usr/share/openshift/examples/infrastructure-templates/enterprise/logging-deployer.yaml
  59. register: template_output
  60. failed_when: "template_output.rc == 1 and 'exists' not in template_output.stderr"
  61. - name: "Process the deployer template"
  62. shell: "{{ openshift.common.client_binary }} --config={{ mktemp.stdout }}/admin.kubeconfig process logging-deployer-template -v {{ oc_process_values }} | {{ openshift.common.client_binary }} --config={{ mktemp.stdout }}/admin.kubeconfig create -f -"
  63. register: process_deployer
  64. failed_when: process_deployer.rc == 1 and 'already exists' not in process_deployer.stderr
  65. - name: "Wait for image pull and deployer pod"
  66. shell: "{{ openshift.common.client_binary }} --config={{ mktemp.stdout }}/admin.kubeconfig get pods | grep logging-deployer.*Completed"
  67. register: result
  68. until: result.rc == 0
  69. retries: 15
  70. delay: 10
  71. - name: "Process support template"
  72. shell: "{{ openshift.common.client_binary }} --config={{ mktemp.stdout }}/admin.kubeconfig process logging-support-template | {{ openshift.common.client_binary }} --config={{ mktemp.stdout }}/admin.kubeconfig create -f -"
  73. register: process_support
  74. failed_when: process_support.rc == 1 and 'already exists' not in process_support.stderr
  75. - name: "Set insecured registry"
  76. command: "{{ openshift.common.client_binary }} --config={{ mktemp.stdout }}/admin.kubeconfig annotate is --all openshift.io/image.insecureRepository=true --overwrite"
  77. when: "target_registry is defined and insecure_registry == 'true'"
  78. - name: "Wait for imagestreams to become available"
  79. shell: "{{ openshift.common.client_binary }} --config={{ mktemp.stdout }}/admin.kubeconfig get is | grep logging-fluentd"
  80. register: result
  81. until: result.rc == 0
  82. failed_when: result.rc == 1 and 'not found' not in result.stderr
  83. retries: 20
  84. delay: 10
  85. - name: "Wait for replication controllers to become available"
  86. shell: "{{ openshift.common.client_binary }} --config={{ mktemp.stdout }}/admin.kubeconfig get rc | grep logging-fluentd-1"
  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: 10
  92. - name: "Scale fluentd deployment config"
  93. command: >
  94. {{ openshift.common.client_binary }} --config={{ mktemp.stdout }}/admin.kubeconfig scale dc/logging-fluentd --replicas={{ fluentd_replicas | default('1') }}
  95. - debug:
  96. msg: "Logging components deployed. Note persistant volume for elasticsearch must be setup manually"
  97. - name: Delete temp directory
  98. file:
  99. name: "{{ mktemp.stdout }}"
  100. state: absent
  101. changed_when: False