launch_instances.yml 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. ---
  2. # TODO: when we are ready to go to ansible 1.9+ support only, we can update to
  3. # the gce task to use the disk_auto_delete parameter to avoid having to delete
  4. # the disk as a separate step on termination
  5. - name: Launch instance(s)
  6. gce:
  7. instance_names: "{{ instances }}"
  8. machine_type: "{{ gce_machine_type | default(deployment_vars[deployment_type].machine_type, true) }}"
  9. image: "{{ gce_machine_image | default(deployment_vars[deployment_type].image, true) }}"
  10. service_account_email: "{{ lookup('env', 'gce_service_account_email_address') }}"
  11. pem_file: "{{ lookup('env', 'gce_service_account_pem_file_path') }}"
  12. project_id: "{{ lookup('env', 'gce_project_id') }}"
  13. zone: "{{ lookup('env', 'zone') }}"
  14. network: "{{ lookup('env', 'network') }}"
  15. # unsupported in 1.9.+
  16. #service_account_permissions: "datastore,logging-write"
  17. tags:
  18. - created-by-{{ lookup('env', 'LOGNAME') |default(cluster, true) }}
  19. - env-{{ cluster }}
  20. - host-type-{{ type }}
  21. - sub-host-type-{{ g_sub_host_type }}
  22. when: instances |length > 0
  23. register: gce
  24. - set_fact:
  25. node_label:
  26. # There doesn't seem to be a way to get the region directly, so parse it out of the zone.
  27. region: "{{ gce.zone | regex_replace('^(.*)-.*$', '\\\\1') }}"
  28. type: "{{ g_sub_host_type }}"
  29. when: instances |length > 0 and type == "node"
  30. - set_fact:
  31. node_label:
  32. # There doesn't seem to be a way to get the region directly, so parse it out of the zone.
  33. region: "{{ gce.zone | regex_replace('^(.*)-.*$', '\\\\1') }}"
  34. type: "{{ type }}"
  35. when: instances |length > 0 and type != "node"
  36. - name: Add new instances to groups and set variables needed
  37. add_host:
  38. hostname: "{{ item.name }}"
  39. ansible_ssh_host: "{{ item.public_ip }}"
  40. ansible_ssh_user: "{{ deployment_vars[deployment_type].ssh_user | default(ansible_ssh_user, true) }}"
  41. ansible_sudo: "{{ deployment_vars[deployment_type].sudo }}"
  42. groups: "{{ item.tags | oo_prepend_strings_in_list('tag_') | join(',') }}"
  43. gce_public_ip: "{{ item.public_ip }}"
  44. gce_private_ip: "{{ item.private_ip }}"
  45. openshift_node_labels: "{{ node_label }}"
  46. with_items: gce.instance_data | default([], true)
  47. - name: Wait for ssh
  48. wait_for: port=22 host={{ item.public_ip }}
  49. with_items: gce.instance_data | default([], true)
  50. - name: Wait for user setup
  51. command: "ssh -o StrictHostKeyChecking=no -o PasswordAuthentication=no -o ConnectTimeout=10 -o UserKnownHostsFile=/dev/null {{ hostvars[item.name].ansible_ssh_user }}@{{ item.public_ip }} echo {{ hostvars[item.name].ansible_ssh_user }} user is setup"
  52. register: result
  53. until: result.rc == 0
  54. retries: 30
  55. delay: 5
  56. with_items: gce.instance_data | default([], true)