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.

77 lines
2.7 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. ci_job_name: "{{ lookup('env', 'CI_JOB_NAME') }}"
  10. delete_group_vars: no
  11. tasks:
  12. - name: include vars for test {{ ci_job_name }}
  13. include_vars: "../files/{{ ci_job_name }}.yml"
  14. - name: replace_test_id
  15. set_fact:
  16. test_name: "{{ test_id |regex_replace('\\.', '-') }}"
  17. - name: set instance names
  18. set_fact:
  19. instance_names: >-
  20. {%- if mode in ['separate', 'separate-scale', 'ha', 'ha-scale'] -%}
  21. k8s-{{ test_name }}-1,k8s-{{ test_name }}-2,k8s-{{ test_name }}-3
  22. {%- elif mode == 'aio' -%}
  23. k8s-{{ test_name }}-1
  24. {%- else -%}
  25. k8s-{{ test_name }}-1,k8s-{{ test_name }}-2
  26. {%- endif -%}
  27. - name: Create gce instances
  28. google.cloud.gcp_compute_instance:
  29. instance_names: "{{ instance_names }}"
  30. machine_type: "{{ cloud_machine_type }}"
  31. image: "{{ cloud_image | default(omit) }}"
  32. image_family: "{{ cloud_image_family | default(omit) }}"
  33. preemptible: "{{ preemptible }}"
  34. service_account_email: "{{ gce_service_account_email }}"
  35. pem_file: "{{ gce_pem_file | default(omit) }}"
  36. credentials_file: "{{ gce_credentials_file | default(omit) }}"
  37. project_id: "{{ gce_project_id }}"
  38. zone: "{{ cloud_region }}"
  39. metadata: '{"test_id": "{{ test_id }}", "network": "{{ kube_network_plugin }}", "startup-script": "{{ startup_script|default("") }}"}'
  40. tags: "build-{{ test_name }},{{ kube_network_plugin }}"
  41. ip_forward: yes
  42. service_account_permissions: ['compute-rw']
  43. register: gce
  44. - name: Add instances to host group
  45. add_host: hostname={{ item.public_ip }} groupname="waitfor_hosts"
  46. with_items: '{{ gce.instance_data }}'
  47. - name: Template the inventory # noqa 404 CI inventory templates are not in role_path
  48. template:
  49. src: ../templates/inventory-gce.j2
  50. dest: "{{ inventory_path }}"
  51. mode: 0644
  52. - name: Make group_vars directory
  53. file:
  54. path: "{{ inventory_path|dirname }}/group_vars"
  55. state: directory
  56. mode: 0755
  57. when: mode in ['scale', 'separate-scale', 'ha-scale']
  58. - name: Template fake hosts group vars # noqa 404 CI templates are not in role_path
  59. template:
  60. src: ../templates/fake_hosts.yml.j2
  61. dest: "{{ inventory_path|dirname }}/group_vars/fake_hosts.yml"
  62. mode: 0644
  63. when: mode in ['scale', 'separate-scale', 'ha-scale']
  64. - name: Delete group_vars directory
  65. file:
  66. path: "{{ inventory_path|dirname }}/group_vars"
  67. state: absent
  68. recurse: yes
  69. when: delete_group_vars