launch.yml 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. ---
  2. - name: Launch instance(s)
  3. hosts: localhost
  4. become: no
  5. connection: local
  6. gather_facts: no
  7. vars_files:
  8. - vars.yml
  9. tasks:
  10. - fail:
  11. msg: "Deployment type not supported for OpenStack provider yet"
  12. when: deployment_type == 'online'
  13. # TODO: Write an Ansible module for dealing with HEAT stacks
  14. # Dealing with the outputs is currently terrible
  15. - name: Check OpenStack stack
  16. command: 'heat stack-show openshift-ansible-{{ cluster_id }}-stack'
  17. register: stack_show_result
  18. changed_when: false
  19. failed_when: stack_show_result.rc != 0 and 'Stack not found' not in stack_show_result.stderr
  20. - set_fact:
  21. heat_stack_action: 'stack-create'
  22. when: stack_show_result.rc == 1
  23. - set_fact:
  24. heat_stack_action: 'stack-update'
  25. when: stack_show_result.rc == 0
  26. - name: Create or Update OpenStack Stack
  27. command: 'heat {{ heat_stack_action }} -f {{ openstack_infra_heat_stack }}
  28. --timeout 3 --enable-rollback
  29. -P cluster_env={{ cluster_env }}
  30. -P cluster_id={{ cluster_id }}
  31. -P subnet_24_prefix={{ openstack_subnet_24_prefix }}
  32. -P dns_nameservers={{ openstack_network_dns | join(",") }}
  33. -P external_net={{ openstack_network_external_net }}
  34. -P ssh_public_key="{{ openstack_ssh_public_key }}"
  35. -P ssh_incoming={{ openstack_ssh_access_from }}
  36. -P num_etcd={{ num_etcd }}
  37. -P num_masters={{ num_masters }}
  38. -P num_nodes={{ num_nodes }}
  39. -P num_infra={{ num_infra }}
  40. -P etcd_image={{ deployment_vars[deployment_type].image }}
  41. -P master_image={{ deployment_vars[deployment_type].image }}
  42. -P node_image={{ deployment_vars[deployment_type].image }}
  43. -P infra_image={{ deployment_vars[deployment_type].image }}
  44. -P dns_image={{ deployment_vars[deployment_type].image }}
  45. -P etcd_flavor={{ openstack_flavor["etcd"] }}
  46. -P master_flavor={{ openstack_flavor["master"] }}
  47. -P node_flavor={{ openstack_flavor["node"] }}
  48. -P infra_flavor={{ openstack_flavor["infra"] }}
  49. -P dns_flavor=m1.small
  50. openshift-ansible-{{ cluster_id }}-stack'
  51. - name: Wait for OpenStack Stack readiness
  52. shell: 'heat stack-show openshift-ansible-{{ cluster_id }}-stack | awk ''$2 == "stack_status" {print $4}'''
  53. register: stack_show_status_result
  54. until: stack_show_status_result.stdout not in ['CREATE_IN_PROGRESS', 'UPDATE_IN_PROGRESS']
  55. retries: 30
  56. delay: 5
  57. failed_when: stack_show_status_result.stdout not in ['CREATE_COMPLETE', 'UPDATE_COMPLETE']
  58. - name: Read OpenStack Stack outputs
  59. command: 'heat stack-show openshift-ansible-{{ cluster_id }}-stack'
  60. register: stack_show_result
  61. - set_fact:
  62. parsed_outputs: "{{ stack_show_result | oo_parse_heat_stack_outputs }}"
  63. - name: Add new etcd instances groups and variables
  64. add_host:
  65. hostname: '{{ item[0] }}'
  66. ansible_ssh_host: '{{ item[2] }}'
  67. ansible_ssh_user: "{{ deployment_vars[deployment_type].ssh_user }}"
  68. ansible_sudo: "{{ deployment_vars[deployment_type].sudo }}"
  69. groups: 'tag_environment_{{ cluster_env }}, tag_host-type_etcd, tag_sub-host-type_default, tag_clusterid_{{ cluster_id }}'
  70. openshift_node_labels:
  71. type: "etcd"
  72. with_together:
  73. - parsed_outputs.etcd_names
  74. - parsed_outputs.etcd_ips
  75. - parsed_outputs.etcd_floating_ips
  76. - name: Add new master instances groups and variables
  77. add_host:
  78. hostname: '{{ item[0] }}'
  79. ansible_ssh_host: '{{ item[2] }}'
  80. ansible_ssh_user: "{{ deployment_vars[deployment_type].ssh_user }}"
  81. ansible_sudo: "{{ deployment_vars[deployment_type].sudo }}"
  82. groups: 'tag_environment_{{ cluster_env }}, tag_host-type_master, tag_sub-host-type_default, tag_clusterid_{{ cluster_id }}'
  83. openshift_node_labels:
  84. type: "master"
  85. with_together:
  86. - parsed_outputs.master_names
  87. - parsed_outputs.master_ips
  88. - parsed_outputs.master_floating_ips
  89. - name: Add new node instances groups and variables
  90. add_host:
  91. hostname: '{{ item[0] }}'
  92. ansible_ssh_host: '{{ item[2] }}'
  93. ansible_ssh_user: "{{ deployment_vars[deployment_type].ssh_user }}"
  94. ansible_sudo: "{{ deployment_vars[deployment_type].sudo }}"
  95. groups: 'tag_environment_{{ cluster_env }}, tag_host-type_node, tag_sub-host-type_compute, tag_clusterid_{{ cluster_id }}'
  96. openshift_node_labels:
  97. type: "compute"
  98. with_together:
  99. - parsed_outputs.node_names
  100. - parsed_outputs.node_ips
  101. - parsed_outputs.node_floating_ips
  102. - name: Add new infra instances groups and variables
  103. add_host:
  104. hostname: '{{ item[0] }}'
  105. ansible_ssh_host: '{{ item[2] }}'
  106. ansible_ssh_user: "{{ deployment_vars[deployment_type].ssh_user }}"
  107. ansible_sudo: "{{ deployment_vars[deployment_type].sudo }}"
  108. groups: 'tag_environment_{{ cluster_env }}, tag_host-type_node, tag_sub-host-type_infra, tag_clusterid_{{ cluster_id }}'
  109. openshift_node_labels:
  110. type: "infra"
  111. with_together:
  112. - parsed_outputs.infra_names
  113. - parsed_outputs.infra_ips
  114. - parsed_outputs.infra_floating_ips
  115. - name: Add DNS groups and variables
  116. add_host:
  117. hostname: '{{ parsed_outputs.dns_name }}'
  118. ansible_ssh_host: '{{ parsed_outputs.dns_floating_ip }}'
  119. ansible_ssh_user: "{{ deployment_vars[deployment_type].ssh_user }}"
  120. ansible_sudo: "{{ deployment_vars[deployment_type].sudo }}"
  121. groups: '{{ cluster_id }}-dns'
  122. - name: Wait for ssh
  123. wait_for:
  124. host: '{{ item }}'
  125. port: 22
  126. with_flattened:
  127. - parsed_outputs.master_floating_ips
  128. - parsed_outputs.node_floating_ips
  129. - parsed_outputs.infra_floating_ips
  130. - parsed_outputs.dns_floating_ip
  131. - name: Wait for user setup
  132. command: 'ssh -o StrictHostKeyChecking=no -o PasswordAuthentication=no -o ConnectTimeout=10 -o UserKnownHostsFile=/dev/null {{ deployment_vars[deployment_type].ssh_user }}@{{ item }} echo {{ deployment_vars[deployment_type].ssh_user }} user is setup'
  133. register: result
  134. until: result.rc == 0
  135. retries: 30
  136. delay: 1
  137. with_flattened:
  138. - parsed_outputs.master_floating_ips
  139. - parsed_outputs.node_floating_ips
  140. - parsed_outputs.infra_floating_ips
  141. - parsed_outputs.dns_floating_ip
  142. - include: update.yml
  143. - include: list.yml