main.yaml 3.5 KB

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