launch_instances.yml 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. ---
  2. - name: Launch instance(s)
  3. gce:
  4. instance_names: "{{ instances|join(',') }}"
  5. machine_type: "{{ gce_machine_type | default(deployment_vars[deployment_type].machine_type, true) }}"
  6. image: "{{ gce_machine_image | default(deployment_vars[deployment_type].image, true) }}"
  7. service_account_email: "{{ lookup('env', 'gce_service_account_email_address') }}"
  8. pem_file: "{{ lookup('env', 'gce_service_account_pem_file_path') }}"
  9. project_id: "{{ lookup('env', 'gce_project_id') }}"
  10. zone: "{{ lookup('env', 'zone') }}"
  11. network: "{{ lookup('env', 'network') }}"
  12. # unsupported in 1.9.+
  13. #service_account_permissions: "datastore,logging-write"
  14. tags:
  15. - created-by-{{ lookup('env', 'LOGNAME') |default(cluster, true) }}
  16. - environment-{{ cluster_env }}
  17. - clusterid-{{ cluster_id }}
  18. - host-type-{{ type }}
  19. - sub-host-type-{{ g_sub_host_type }}
  20. metadata:
  21. startup-script: |
  22. #!/bin/bash
  23. echo "Defaults:{{ deployment_vars[deployment_type].ssh_user }} !requiretty" > /etc/sudoers.d/99-{{ deployment_vars[deployment_type].ssh_user }}
  24. when: instances |length > 0
  25. register: gce
  26. - set_fact:
  27. node_label:
  28. # There doesn't seem to be a way to get the region directly, so parse it out of the zone.
  29. region: "{{ gce.zone | regex_replace('^(.*)-.*$', '\\\\1') }}"
  30. type: "{{ g_sub_host_type }}"
  31. when: instances |length > 0 and type == "node"
  32. - set_fact:
  33. node_label:
  34. # There doesn't seem to be a way to get the region directly, so parse it out of the zone.
  35. region: "{{ gce.zone | regex_replace('^(.*)-.*$', '\\\\1') }}"
  36. type: "{{ type }}"
  37. when: instances |length > 0 and type != "node"
  38. - name: Add new instances to groups and set variables needed
  39. add_host:
  40. hostname: "{{ item.name }}"
  41. ansible_ssh_host: "{{ item.public_ip }}"
  42. ansible_ssh_user: "{{ deployment_vars[deployment_type].ssh_user }}"
  43. ansible_become: "{{ deployment_vars[deployment_type].become }}"
  44. groups: "{{ item.tags | oo_prepend_strings_in_list('tag_') | join(',') }}"
  45. gce_public_ip: "{{ item.public_ip }}"
  46. gce_private_ip: "{{ item.private_ip }}"
  47. openshift_node_labels: "{{ node_label }}"
  48. with_items: "{{ gce.instance_data | default([], true) }}"
  49. - name: Wait for ssh
  50. wait_for: port=22 host={{ item.public_ip }}
  51. with_items: "{{ gce.instance_data | default([], true) }}"
  52. - name: Wait for user setup
  53. 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"
  54. register: result
  55. until: result.rc == 0
  56. retries: 30
  57. delay: 5
  58. with_items: "{{ gce.instance_data | default([], true) }}"