launch.yml 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. ---
  2. - name: Launch instance(s)
  3. hosts: localhost
  4. connection: local
  5. gather_facts: no
  6. vars_files:
  7. - vars.yml
  8. tasks:
  9. - fail:
  10. msg: "Deployment type not supported for OpenStack provider yet"
  11. when: deployment_type == 'online'
  12. # TODO: Write an Ansible module for dealing with HEAT stacks
  13. # Dealing with the outputs is currently terrible
  14. - name: Check OpenStack stack
  15. command: 'heat stack-show openshift-ansible-{{ cluster_id }}-stack'
  16. register: stack_show_result
  17. changed_when: false
  18. failed_when: stack_show_result.rc != 0 and 'Stack not found' not in stack_show_result.stderr
  19. - name: Create OpenStack Stack
  20. command: 'heat stack-create -f {{ openstack_infra_heat_stack }}
  21. -P cluster_id={{ cluster_id }}
  22. -P dns_nameservers={{ openstack_network_dns | join(",") }}
  23. -P cidr={{ openstack_network_cidr }}
  24. -P ssh_incoming={{ openstack_ssh_access_from }}
  25. -P num_masters={{ num_masters }}
  26. -P num_nodes={{ num_nodes }}
  27. -P num_infra={{ num_infra }}
  28. -P master_image={{ deployment_vars[deployment_type].image }}
  29. -P node_image={{ deployment_vars[deployment_type].image }}
  30. -P infra_image={{ deployment_vars[deployment_type].image }}
  31. -P master_flavor={{ openstack_flavor["master"] }}
  32. -P node_flavor={{ openstack_flavor["node"] }}
  33. -P infra_flavor={{ openstack_flavor["infra"] }}
  34. -P ssh_public_key="{{ openstack_ssh_public_key }}"
  35. openshift-ansible-{{ cluster_id }}-stack'
  36. when: stack_show_result.rc == 1
  37. - name: Update OpenStack Stack
  38. command: 'heat stack-update -f {{ openstack_infra_heat_stack }}
  39. -P cluster_id={{ cluster_id }}
  40. -P dns_nameservers={{ openstack_network_dns | join(",") }}
  41. -P cidr={{ openstack_network_cidr }}
  42. -P ssh_incoming={{ openstack_ssh_access_from }}
  43. -P num_masters={{ num_masters }}
  44. -P num_nodes={{ num_nodes }}
  45. -P num_infra={{ num_infra }}
  46. -P master_image={{ deployment_vars[deployment_type].image }}
  47. -P node_image={{ deployment_vars[deployment_type].image }}
  48. -P infra_image={{ deployment_vars[deployment_type].image }}
  49. -P master_flavor={{ openstack_flavor["master"] }}
  50. -P node_flavor={{ openstack_flavor["node"] }}
  51. -P infra_flavor={{ openstack_flavor["infra"] }}
  52. -P ssh_public_key="{{ openstack_ssh_public_key }}"
  53. openshift-ansible-{{ cluster_id }}-stack'
  54. when: stack_show_result.rc == 0
  55. - name: Wait for OpenStack Stack readiness
  56. shell: 'heat stack-show openshift-ansible-{{ cluster_id }}-stack | awk ''$2 == "stack_status" {print $4}'''
  57. register: stack_show_status_result
  58. until: stack_show_status_result.stdout not in ['CREATE_IN_PROGRESS', 'UPDATE_IN_PROGRESS']
  59. retries: 30
  60. delay: 1
  61. failed_when: stack_show_status_result.stdout not in ['CREATE_COMPLETE', 'UPDATE_COMPLETE']
  62. - name: Read OpenStack Stack outputs
  63. command: 'heat stack-show openshift-ansible-{{ cluster_id }}-stack'
  64. register: stack_show_result
  65. - set_fact:
  66. parsed_outputs: "{{ stack_show_result | oo_parse_heat_stack_outputs }}"
  67. - name: Add new master instances groups and variables
  68. add_host:
  69. hostname: '{{ item[0] }}'
  70. ansible_ssh_host: '{{ item[2] }}'
  71. ansible_ssh_user: "{{ deployment_vars[deployment_type].ssh_user }}"
  72. ansible_sudo: "{{ deployment_vars[deployment_type].sudo }}"
  73. groups: 'tag_env_{{ cluster_id }}, tag_host-type_master, tag_env-host-type_{{ cluster_id }}-openshift-master, tag_sub-host-type_default'
  74. with_together:
  75. - parsed_outputs.master_names
  76. - parsed_outputs.master_ips
  77. - parsed_outputs.master_floating_ips
  78. - name: Add new node instances groups and variables
  79. add_host:
  80. hostname: '{{ item[0] }}'
  81. ansible_ssh_host: '{{ item[2] }}'
  82. ansible_ssh_user: "{{ deployment_vars[deployment_type].ssh_user }}"
  83. ansible_sudo: "{{ deployment_vars[deployment_type].sudo }}"
  84. groups: 'tag_env_{{ cluster_id }}, tag_host-type_node, tag_env-host-type_{{ cluster_id }}-openshift-node, tag_sub-host-type_compute'
  85. with_together:
  86. - parsed_outputs.node_names
  87. - parsed_outputs.node_ips
  88. - parsed_outputs.node_floating_ips
  89. - name: Add new infra 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_env_{{ cluster_id }}, tag_host-type_node, tag_env-host-type_{{ cluster_id }}-openshift-node, tag_sub-host-type_infra'
  96. with_together:
  97. - parsed_outputs.infra_names
  98. - parsed_outputs.infra_ips
  99. - parsed_outputs.infra_floating_ips
  100. - name: Wait for ssh
  101. wait_for:
  102. host: '{{ item }}'
  103. port: 22
  104. with_flattened:
  105. - parsed_outputs.master_floating_ips
  106. - parsed_outputs.node_floating_ips
  107. - parsed_outputs.infra_floating_ips
  108. - name: Wait for user setup
  109. 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'
  110. register: result
  111. until: result.rc == 0
  112. retries: 30
  113. delay: 1
  114. with_flattened:
  115. - parsed_outputs.master_floating_ips
  116. - parsed_outputs.node_floating_ips
  117. - parsed_outputs.infra_floating_ips
  118. - include: update.yml
  119. - include: list.yml