launch_instances.yml 2.8 KB

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