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.

74 lines
2.6 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. gce:
  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. - name: Make group_vars directory
  52. file:
  53. path: "{{ inventory_path|dirname }}/group_vars"
  54. state: directory
  55. when: mode in ['scale', 'separate-scale', 'ha-scale']
  56. - name: Template fake hosts group vars # noqa 404 CI templates are not in role_path
  57. template:
  58. src: ../templates/fake_hosts.yml.j2
  59. dest: "{{ inventory_path|dirname }}/group_vars/fake_hosts.yml"
  60. when: mode in ['scale', 'separate-scale', 'ha-scale']
  61. - name: Delete group_vars directory
  62. file:
  63. path: "{{ inventory_path|dirname }}/group_vars"
  64. state: absent
  65. recurse: yes
  66. when: delete_group_vars