launch.yml 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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 cidr={{ openstack_network_cidr }}
  32. -P dns_nameservers={{ openstack_network_dns | join(",") }}
  33. -P external_net={{ openstack_network_external_net }}
  34. -P floating_ip_pool={{ openstack_floating_ip_pool }}
  35. -P ssh_public_key="{{ openstack_ssh_public_key }}"
  36. -P ssh_incoming={{ openstack_ssh_access_from }}
  37. -P num_etcd={{ num_etcd }}
  38. -P num_masters={{ num_masters }}
  39. -P num_nodes={{ num_nodes }}
  40. -P num_infra={{ num_infra }}
  41. -P etcd_image={{ deployment_vars[deployment_type].image }}
  42. -P master_image={{ deployment_vars[deployment_type].image }}
  43. -P node_image={{ deployment_vars[deployment_type].image }}
  44. -P infra_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. openshift-ansible-{{ cluster_id }}-stack'
  50. - name: Wait for OpenStack Stack readiness
  51. shell: 'heat stack-show openshift-ansible-{{ cluster_id }}-stack | awk ''$2 == "stack_status" {print $4}'''
  52. register: stack_show_status_result
  53. until: stack_show_status_result.stdout not in ['CREATE_IN_PROGRESS', 'UPDATE_IN_PROGRESS']
  54. retries: 30
  55. delay: 5
  56. failed_when: stack_show_status_result.stdout not in ['CREATE_COMPLETE', 'UPDATE_COMPLETE']
  57. - name: Read OpenStack Stack outputs
  58. command: 'heat stack-show openshift-ansible-{{ cluster_id }}-stack'
  59. register: stack_show_result
  60. - set_fact:
  61. parsed_outputs: "{{ stack_show_result | oo_parse_heat_stack_outputs }}"
  62. - name: Add new etcd instances groups and variables
  63. add_host:
  64. hostname: '{{ item[0] }}'
  65. ansible_ssh_host: '{{ item[2] }}'
  66. ansible_ssh_user: "{{ deployment_vars[deployment_type].ssh_user }}"
  67. ansible_sudo: "{{ deployment_vars[deployment_type].sudo }}"
  68. groups: 'tag_environment_{{ cluster_env }}, tag_host-type_etcd, tag_sub-host-type_default, tag_clusterid_{{ cluster_id }}'
  69. with_together:
  70. - parsed_outputs.etcd_names
  71. - parsed_outputs.etcd_ips
  72. - parsed_outputs.etcd_floating_ips
  73. - name: Add new master instances groups and variables
  74. add_host:
  75. hostname: '{{ item[0] }}'
  76. ansible_ssh_host: '{{ item[2] }}'
  77. ansible_ssh_user: "{{ deployment_vars[deployment_type].ssh_user }}"
  78. ansible_sudo: "{{ deployment_vars[deployment_type].sudo }}"
  79. groups: 'tag_environment_{{ cluster_env }}, tag_host-type_master, tag_sub-host-type_default, tag_clusterid_{{ cluster_id }}'
  80. with_together:
  81. - parsed_outputs.master_names
  82. - parsed_outputs.master_ips
  83. - parsed_outputs.master_floating_ips
  84. - name: Add new node instances groups and variables
  85. add_host:
  86. hostname: '{{ item[0] }}'
  87. ansible_ssh_host: '{{ item[2] }}'
  88. ansible_ssh_user: "{{ deployment_vars[deployment_type].ssh_user }}"
  89. ansible_sudo: "{{ deployment_vars[deployment_type].sudo }}"
  90. groups: 'tag_environment_{{ cluster_env }}, tag_host-type_node, tag_sub-host-type_compute, tag_clusterid_{{ cluster_id }}'
  91. with_together:
  92. - parsed_outputs.node_names
  93. - parsed_outputs.node_ips
  94. - parsed_outputs.node_floating_ips
  95. - name: Add new infra instances groups and variables
  96. add_host:
  97. hostname: '{{ item[0] }}'
  98. ansible_ssh_host: '{{ item[2] }}'
  99. ansible_ssh_user: "{{ deployment_vars[deployment_type].ssh_user }}"
  100. ansible_sudo: "{{ deployment_vars[deployment_type].sudo }}"
  101. groups: 'tag_environment_{{ cluster_env }}, tag_host-type_node, tag_sub-host-type_infra, tag_clusterid_{{ cluster_id }}'
  102. with_together:
  103. - parsed_outputs.infra_names
  104. - parsed_outputs.infra_ips
  105. - parsed_outputs.infra_floating_ips
  106. - name: Wait for ssh
  107. wait_for:
  108. host: '{{ item }}'
  109. port: 22
  110. with_flattened:
  111. - parsed_outputs.master_floating_ips
  112. - parsed_outputs.node_floating_ips
  113. - parsed_outputs.infra_floating_ips
  114. - name: Wait for user setup
  115. 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'
  116. register: result
  117. until: result.rc == 0
  118. retries: 30
  119. delay: 1
  120. with_flattened:
  121. - parsed_outputs.master_floating_ips
  122. - parsed_outputs.node_floating_ips
  123. - parsed_outputs.infra_floating_ips
  124. - include: update.yml
  125. - include: list.yml