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.

66 lines
2.1 KiB

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