launch_instances.yml 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. - set_fact:
  6. machine_type: "{{ lookup('env', 'gce_machine_type') |default('n1-standard-1', true) }}"
  7. machine_image: "{{ lookup('env', 'gce_machine_image') |default('libra-rhel7', true) }}"
  8. - name: Launch instance(s)
  9. gce:
  10. instance_names: "{{ instances }}"
  11. machine_type: "{{ machine_type }}"
  12. image: "{{ machine_image }}"
  13. service_account_email: "{{ lookup('env', 'gce_service_account_email_address') }}"
  14. pem_file: "{{ lookup('env', 'gce_service_account_pem_file_path') }}"
  15. project_id: "{{ lookup('env', 'gce_project_id') }}"
  16. tags:
  17. - "created-by-{{ lookup('env', 'LOGNAME') |default(cluster, true) }}"
  18. - "env-{{ cluster }}"
  19. - "host-type-{{ type }}"
  20. - "env-host-type-{{ cluster }}-openshift-{{ type }}"
  21. register: gce
  22. - name: Add new instances to groups and set variables needed
  23. add_host:
  24. hostname: "{{ item.name }}"
  25. ansible_ssh_host: "{{ item.public_ip }}"
  26. groups: "{{ item.tags | oo_prepend_strings_in_list('tag_') | join(',') }}"
  27. gce_public_ip: "{{ item.public_ip }}"
  28. gce_private_ip: "{{ item.private_ip }}"
  29. with_items: gce.instance_data
  30. - name: Wait for ssh
  31. wait_for: "port=22 host={{ item.public_ip }}"
  32. with_items: gce.instance_data
  33. - name: Wait for root user setup
  34. command: "ssh -o StrictHostKeyChecking=no -o PasswordAuthentication=no -o ConnectTimeout=10 -o UserKnownHostsFile=/dev/null root@{{ item.public_ip }} echo root user is setup"
  35. register: result
  36. until: result.rc == 0
  37. retries: 20
  38. delay: 10
  39. with_items: gce.instance_data