You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
2.3 KiB

  1. ---
  2. - hosts: localhost
  3. become: false
  4. gather_facts: no
  5. vars:
  6. cloud_machine_type: g1-small
  7. mode: default
  8. preemptible: no
  9. tasks:
  10. - name: replace_test_id
  11. set_fact:
  12. test_name: "{{test_id |regex_replace('\\.', '-')}}"
  13. - set_fact:
  14. instance_names: >-
  15. {%- if mode in ['separate', 'separate-scale', 'ha', 'ha-scale'] -%}
  16. k8s-{{test_name}}-1,k8s-{{test_name}}-2,k8s-{{test_name}}-3
  17. {%- elif mode == 'aio' -%}
  18. k8s-{{test_name}}-1
  19. {%- else -%}
  20. k8s-{{test_name}}-1,k8s-{{test_name}}-2
  21. {%- endif -%}
  22. - name: Create gce instances
  23. gce:
  24. instance_names: "{{instance_names}}"
  25. machine_type: "{{ cloud_machine_type }}"
  26. image_family: "{{ cloud_image }}"
  27. preemptible: "{{ preemptible }}"
  28. service_account_email: "{{ gce_service_account_email }}"
  29. pem_file: "{{ gce_pem_file | default(omit)}}"
  30. credentials_file: "{{gce_credentials_file | default(omit)}}"
  31. project_id: "{{ gce_project_id }}"
  32. zone: "{{cloud_region}}"
  33. metadata: '{"test_id": "{{test_id}}", "network": "{{kube_network_plugin}}", "startup-script": "{{startup_script}}"}'
  34. tags: "build-{{test_name}},{{kube_network_plugin}}"
  35. ip_forward: yes
  36. service_account_permissions: ['compute-rw']
  37. register: gce
  38. - name: Add instances to host group
  39. add_host: hostname={{item.public_ip}} groupname="waitfor_hosts"
  40. with_items: '{{gce.instance_data}}'
  41. - name: Template the inventory
  42. template:
  43. src: ../templates/inventory-gce.j2
  44. dest: "{{ inventory_path }}"
  45. - name: Make group_vars directory
  46. file:
  47. path: "{{ inventory_path|dirname }}/group_vars"
  48. state: directory
  49. when: mode in ['scale', 'separate-scale', 'ha-scale']
  50. - name: Template fake hosts group vars
  51. template:
  52. src: ../templates/fake_hosts.yml.j2
  53. dest: "{{ inventory_path|dirname }}/group_vars/fake_hosts.yml"
  54. when: mode in ['scale', 'separate-scale', 'ha-scale']
  55. - name: Wait for instances
  56. hosts: "waitfor_hosts"
  57. gather_facts: false
  58. tasks:
  59. - name: Wait for SSH to come up.
  60. local_action: wait_for host={{inventory_hostname}} port=22 delay=60 timeout=240 state=started