main.yaml 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. ---
  2. - name: Create temp directory for kubeconfig
  3. command: mktemp -d /tmp/openshift-ansible-XXXXXX
  4. register: mktemp
  5. changed_when: False
  6. - name: Record kubeconfig tmp dir
  7. set_fact:
  8. openshift_metrics_kubeconfig: "{{ mktemp.stdout }}/admin.kubeconfig"
  9. - name: Copy the admin client config(s)
  10. command: >
  11. cp {{ openshift_master_config_dir }}/admin.kubeconfig {{ openshift_metrics_kubeconfig }}
  12. changed_when: False
  13. - name: Set hosted metrics facts
  14. openshift_facts:
  15. role: hosted
  16. openshift_env: "{{ hostvars
  17. | oo_merge_hostvars(vars, inventory_hostname)
  18. | oo_openshift_env }}"
  19. openshift_env_structures:
  20. - 'openshift.hosted.metrics.*'
  21. - set_fact:
  22. metrics_persistence: "{{ openshift.hosted.metrics.storage_kind | default(none) is not none }}"
  23. metrics_dynamic_vol: "{{ openshift.hosted.metrics.storage_kind | default(none) == 'dynamic' }}"
  24. metrics_template_dir: "{{ openshift.common.config_base if openshift.common.is_containerized | bool else '/usr/share/openshift' }}/examples/infrastructure-templates/{{ 'origin' if deployment_type == 'origin' else 'enterprise' }}"
  25. image_prefix: "{{ '-v IMAGE_PREFIX=' ~ openshift.hosted.metrics.deployer.prefix if 'prefix' in openshift.hosted.metrics.deployer else '' }}"
  26. image_version: "{{ '-v IMAGE_VERSION=' ~ openshift.hosted.metrics.deployer.version if 'version' in openshift.hosted.metrics.deployer else '' }}"
  27. - name: Check for existing metrics pods
  28. shell: >
  29. {{ openshift.common.client_binary }}
  30. --config={{ openshift_metrics_kubeconfig }}
  31. --namespace openshift-infra
  32. get pods -l {{ item }} | grep -q Running
  33. register: metrics_pods_status
  34. with_items:
  35. - metrics-infra=hawkular-metrics
  36. - metrics-infra=heapster
  37. - metrics-infra=hawkular-cassandra
  38. failed_when: false
  39. changed_when: false
  40. - name: Check for previous deployer
  41. shell: >
  42. {{ openshift.common.client_binary }}
  43. --config={{ openshift_metrics_kubeconfig }}
  44. --namespace openshift-infra
  45. get pods -l metrics-infra=deployer --sort-by='{.metadata.creationTimestamp}' | tail -1 | grep metrics-deployer-
  46. register: metrics_deployer_status
  47. failed_when: false
  48. changed_when: false
  49. - name: Record current deployment status
  50. set_fact:
  51. greenfield: "{{ not metrics_deployer_status.rc == 0 }}"
  52. failed_error: "{{ True if 'Error' in metrics_deployer_status.stdout else False }}"
  53. metrics_running: "{{ metrics_pods_status.results | oo_collect(attribute='rc') == [0,0,0] }}"
  54. - name: Set deployment mode
  55. set_fact:
  56. deployment_mode: "{{ 'refresh' if (failed_error | bool or metrics_upgrade | bool) else 'deploy' }}"
  57. # TODO: handle non greenfield deployments in the future
  58. - include: install.yml
  59. when: greenfield
  60. - name: Delete temp directory
  61. file:
  62. name: "{{ mktemp.stdout }}"
  63. state: absent
  64. changed_when: False