openshift_hosted.yml 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. ---
  2. - name: Create persistent volumes
  3. hosts: oo_first_master
  4. tags:
  5. - hosted
  6. vars:
  7. persistent_volumes: "{{ hostvars[groups.oo_first_master.0] | oo_persistent_volumes(groups) }}"
  8. persistent_volume_claims: "{{ hostvars[groups.oo_first_master.0] | oo_persistent_volume_claims }}"
  9. roles:
  10. - role: openshift_persistent_volumes
  11. when: persistent_volumes | length > 0 or persistent_volume_claims | length > 0
  12. - name: Create Hosted Resources
  13. hosts: oo_first_master
  14. tags:
  15. - hosted
  16. pre_tasks:
  17. - set_fact:
  18. openshift_hosted_router_registryurl: "{{ hostvars[groups.oo_first_master.0].openshift.master.registry_url }}"
  19. openshift_hosted_registry_registryurl: "{{ hostvars[groups.oo_first_master.0].openshift.master.registry_url }}"
  20. when: "'master' in hostvars[groups.oo_first_master.0].openshift and 'registry_url' in hostvars[groups.oo_first_master.0].openshift.master"
  21. - set_fact:
  22. logging_hostname: "{{ openshift_hosted_logging_hostname | default('kibana.' ~ (openshift.master.default_subdomain | default('router.default.svc.cluster.local', true))) }}"
  23. logging_ops_hostname: "{{ openshift_hosted_logging_ops_hostname | default('kibana-ops.' ~ (openshift.master.default_subdomain | default('router.default.svc.cluster.local', true))) }}"
  24. logging_master_public_url: "{{ openshift_hosted_logging_master_public_url | default(openshift.master.public_api_url) }}"
  25. logging_elasticsearch_cluster_size: "{{ openshift_hosted_logging_elasticsearch_cluster_size | default(1) }}"
  26. logging_elasticsearch_ops_cluster_size: "{{ openshift_hosted_logging_elasticsearch_ops_cluster_size | default(1) }}"
  27. roles:
  28. - role: openshift_cli
  29. - role: openshift_hosted_facts
  30. - role: openshift_projects
  31. # TODO: Move standard project definitions to openshift_hosted/vars/main.yml
  32. # Vars are not accessible in meta/main.yml in ansible-1.9.x
  33. openshift_projects: "{{ openshift_additional_projects | default({}) | oo_merge_dicts({'default':{'default_node_selector':''},'openshift-infra':{'default_node_selector':''},'logging':{'default_node_selector':''}}) }}"
  34. - role: openshift_serviceaccounts
  35. openshift_serviceaccounts_names:
  36. - router
  37. openshift_serviceaccounts_namespace: default
  38. openshift_serviceaccounts_sccs:
  39. - hostnetwork
  40. when: openshift.common.version_gte_3_2_or_1_2
  41. - role: openshift_serviceaccounts
  42. openshift_serviceaccounts_names:
  43. - router
  44. - registry
  45. openshift_serviceaccounts_namespace: default
  46. openshift_serviceaccounts_sccs:
  47. - privileged
  48. when: not openshift.common.version_gte_3_2_or_1_2
  49. - role: openshift_hosted
  50. - role: openshift_metrics
  51. when: openshift.hosted.metrics.deploy | bool
  52. - role: openshift_hosted_logging
  53. when: openshift.hosted.logging.deploy | bool
  54. openshift_hosted_logging_hostname: "{{ logging_hostname }}"
  55. openshift_hosted_logging_ops_hostname: "{{ logging_ops_hostname }}"
  56. openshift_hosted_logging_master_public_url: "{{ logging_master_public_url }}"
  57. openshift_hosted_logging_elasticsearch_cluster_size: "{{ logging_elasticsearch_cluster_size }}"
  58. openshift_hosted_logging_elasticsearch_pvc_dynamic: "{{ 'true' if openshift.hosted.logging.storage_kind | default(none) == 'dynamic' else 'false' }}"
  59. openshift_hosted_logging_elasticsearch_pvc_size: "{{ openshift.hosted.logging.storage.volume.size if openshift.hosted.logging.storage_kind | default(none) == 'dynamic' else '' }}"
  60. openshift_hosted_logging_elasticsearch_pvc_prefix: "{{ 'logging-es' if openshift.hosted.logging.storage_kind | default(none) is not none else '' }}"
  61. openshift_hosted_logging_elasticsearch_ops_cluster_size: "{{ logging_elasticsearch_ops_cluster_size }}"
  62. openshift_hosted_logging_elasticsearch_ops_pvc_dynamic: "{{ 'true' if openshift.hosted.logging.storage_kind | default(none) == 'dynamic' else 'false' }}"
  63. openshift_hosted_logging_elasticsearch_ops_pvc_size: "{{ openshift.hosted.logging.storage.volume.size if openshift.hosted.logging.storage_kind | default(none) == 'dynamic' else '' }}"
  64. openshift_hosted_logging_elasticsearch_ops_pvc_prefix: "{{ 'logging-es' if openshift.hosted.logging.storage_kind | default(none) is not none else '' }}"
  65. - role: cockpit-ui
  66. when: openshift.common.deployment_subtype == 'registry'
  67. - name: Configure all masters for logging
  68. serial: 1
  69. handlers:
  70. - include: ../../../roles/openshift_master/handlers/main.yml
  71. static: yes
  72. hosts: oo_masters
  73. tasks:
  74. - openshift_facts:
  75. role: master
  76. local_facts:
  77. logging_public_url: "https://{{ openshift_hosted_logging_hostname | default('kibana.' ~ openshift_master_default_subdomain) }}"
  78. when: openshift.hosted.logging.deploy | default(openshift.common.version_gte_3_3_or_1_3)
  79. - modify_yaml:
  80. dest: "{{ openshift.common.config_base }}/master/master-config.yaml"
  81. yaml_key: assetConfig.loggingPublicURL
  82. yaml_value: "{{ openshift.master.logging_public_url }}"
  83. notify: restart master
  84. when: openshift.hosted.logging.deploy | default(openshift.common.version_gte_3_3_or_1_3)
  85. - name: Configure CA certificate for secure registry
  86. hosts: oo_nodes_to_config
  87. tags:
  88. - hosted
  89. tasks:
  90. - name: Create temp directory for kubeconfig
  91. command: mktemp -d /tmp/openshift-ansible-XXXXXX
  92. register: mktemp
  93. when: openshift.common.deployment_subtype == 'registry'
  94. changed_when: false
  95. delegate_to: "{{ groups.oo_first_master.0 }}"
  96. run_once: true
  97. - set_fact:
  98. openshift_hosted_kubeconfig: "{{ mktemp.stdout }}/admin.kubeconfig"
  99. when: openshift.common.deployment_subtype == 'registry'
  100. delegate_to: "{{ groups.oo_first_master.0 }}"
  101. run_once: true
  102. - name: Copy the admin client config(s)
  103. command: >
  104. cp {{ openshift.common.config_base }}/master/admin.kubeconfig {{ openshift_hosted_kubeconfig }}
  105. when: openshift.common.deployment_subtype == 'registry'
  106. changed_when: false
  107. delegate_to: "{{ groups.oo_first_master.0 }}"
  108. run_once: true
  109. - name: Retrieve docker-registry route
  110. command: >
  111. {{ openshift.common.client_binary }} get route docker-registry
  112. --template='{{ '{{' }} .spec.host {{ '}}' }}'
  113. --config={{ openshift_hosted_kubeconfig }}
  114. -n default
  115. register: docker_registry_route
  116. when: openshift.common.deployment_subtype == 'registry'
  117. changed_when: false
  118. delegate_to: "{{ groups.oo_first_master.0 }}"
  119. run_once: true
  120. - name: Retrieve registry service IP
  121. command: >
  122. {{ openshift.common.client_binary }} get service docker-registry
  123. --template='{{ '{{' }} .spec.clusterIP {{ '}}' }}'
  124. --config={{ openshift_hosted_kubeconfig }}
  125. -n default
  126. register: docker_registry_service_ip
  127. when: openshift.common.deployment_subtype == 'registry'
  128. changed_when: false
  129. delegate_to: "{{ groups.oo_first_master.0 }}"
  130. run_once: true
  131. - name: Create registry CA directories
  132. file:
  133. path: "/etc/docker/certs.d/{{ item }}"
  134. state: directory
  135. with_items:
  136. - "{{ docker_registry_service_ip.stdout }}:5000"
  137. - "{{ docker_registry_route.stdout }}"
  138. - "docker-registry.default.svc.cluster.local:5000"
  139. when: openshift.common.deployment_subtype == 'registry'
  140. - name: Copy CA to registry CA directories
  141. copy:
  142. src: "{{ openshift.common.config_base }}/node/ca.crt"
  143. dest: "/etc/docker/certs.d/{{ item }}"
  144. remote_src: yes
  145. force: yes
  146. with_items:
  147. - "{{ docker_registry_service_ip.stdout }}:5000"
  148. - "{{ docker_registry_route.stdout }}"
  149. - "docker-registry.default.svc.cluster.local:5000"
  150. when: openshift.common.deployment_subtype == 'registry'
  151. notify:
  152. - Restart docker
  153. - name: Delete temp directory
  154. file:
  155. name: "{{ mktemp.stdout }}"
  156. state: absent
  157. when: openshift.common.deployment_subtype == 'registry'
  158. changed_when: False
  159. delegate_to: "{{ groups.oo_first_master.0 }}"
  160. run_once: true
  161. handlers:
  162. - name: Restart docker
  163. service:
  164. name: docker
  165. state: restarted