launch.yml 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 master_image={{ deployment_vars[deployment_type].image }}
  28. -P node_image={{ deployment_vars[deployment_type].image }}
  29. -P master_flavor={{ openstack_flavor["master"] }}
  30. -P node_flavor={{ openstack_flavor["node"] }}
  31. -P ssh_public_key="{{ openstack_ssh_public_key }}"
  32. openshift-ansible-{{ cluster_id }}-stack'
  33. when: stack_show_result.rc == 1
  34. - name: Update OpenStack Stack
  35. command: 'heat stack-update -f {{ openstack_infra_heat_stack }}
  36. -P cluster_id={{ cluster_id }}
  37. -P dns_nameservers={{ openstack_network_dns | join(",") }}
  38. -P cidr={{ openstack_network_cidr }}
  39. -P ssh_incoming={{ openstack_ssh_access_from }}
  40. -P num_masters={{ num_masters }}
  41. -P num_nodes={{ num_nodes }}
  42. -P master_image={{ deployment_vars[deployment_type].image }}
  43. -P node_image={{ deployment_vars[deployment_type].image }}
  44. -P master_flavor={{ openstack_flavor["master"] }}
  45. -P node_flavor={{ openstack_flavor["node"] }}
  46. -P ssh_public_key="{{ openstack_ssh_public_key }}"
  47. openshift-ansible-{{ cluster_id }}-stack'
  48. when: stack_show_result.rc == 0
  49. - name: Wait for OpenStack Stack readiness
  50. shell: 'heat stack-show openshift-ansible-{{ cluster_id }}-stack | awk ''$2 == "stack_status" {print $4}'''
  51. register: stack_show_status_result
  52. until: stack_show_status_result.stdout not in ['CREATE_IN_PROGRESS', 'UPDATE_IN_PROGRESS']
  53. retries: 30
  54. delay: 1
  55. failed_when: stack_show_status_result.stdout not in ['CREATE_COMPLETE', 'UPDATE_COMPLETE']
  56. - name: Read OpenStack Stack outputs
  57. command: 'heat stack-show openshift-ansible-{{ cluster_id }}-stack'
  58. register: stack_show_result
  59. - set_fact:
  60. parsed_outputs: "{{ stack_show_result | oo_parse_heat_stack_outputs }}"
  61. - name: Add new master instances groups and variables
  62. add_host:
  63. hostname: '{{ item[0] }}'
  64. ansible_ssh_host: '{{ item[2] }}'
  65. ansible_ssh_user: "{{ deployment_vars[deployment_type].ssh_user }}"
  66. ansible_sudo: "{{ deployment_vars[deployment_type].sudo }}"
  67. groups: 'tag_env_{{ cluster_id }}, tag_host-type_master, tag_env-host-type_{{ cluster_id }}-openshift-master'
  68. with_together:
  69. - parsed_outputs.master_names
  70. - parsed_outputs.master_ips
  71. - parsed_outputs.master_floating_ips
  72. - name: Add new node instances groups and variables
  73. add_host:
  74. hostname: '{{ item[0] }}'
  75. ansible_ssh_host: '{{ item[2] }}'
  76. ansible_ssh_user: "{{ deployment_vars[deployment_type].ssh_user }}"
  77. ansible_sudo: "{{ deployment_vars[deployment_type].sudo }}"
  78. groups: 'tag_env_{{ cluster_id }}, tag_host-type_node, tag_env-host-type_{{ cluster_id }}-openshift-node'
  79. with_together:
  80. - parsed_outputs.node_names
  81. - parsed_outputs.node_ips
  82. - parsed_outputs.node_floating_ips
  83. - name: Wait for ssh
  84. wait_for:
  85. host: '{{ item }}'
  86. port: 22
  87. with_flattened:
  88. - parsed_outputs.master_floating_ips
  89. - parsed_outputs.node_floating_ips
  90. - name: Wait for user setup
  91. 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'
  92. register: result
  93. until: result.rc == 0
  94. retries: 30
  95. delay: 1
  96. with_flattened:
  97. - parsed_outputs.master_floating_ips
  98. - parsed_outputs.node_floating_ips
  99. - include: update.yml
  100. - include: list.yml