Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ansible/ci/group_vars/all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ gcp_instance_prefix: ci
gcp_available_zones:
- us-central1-a
- us-central1-b
- us-central1-c
- us-central1-d
- us-central1-f
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- us-central1-f
- us-central1-f
- us-central1-d

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$ gcloud compute machine-types list --filter="name=t2a-standard-2 AND zone~'^us-'" --format="value(zone)"
us-central1-a
us-central1-b
us-central1-f
us-central1-d

ansible_user: runner
gcp_network_name: collector-ci
Expand Down
1 change: 0 additions & 1 deletion ansible/dev/group_vars/all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ gcp_instance_prefix: "{{ lookup('env', 'USER') }}-dev"
gcp_available_zones:
- us-central1-a
- us-central1-b
- us-central1-c
- us-central1-f
ansible_user: "{{ lookup('env', 'USER') }}"
gcp_network_name: default
Expand Down
39 changes: 39 additions & 0 deletions ansible/roles/create-vm/tasks/create-gcp-instance.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
- name: Safely create GCP compute instance
block:
- name: Create compute instance
google.cloud.gcp_compute_instance:
name: "{{ vm_name }}"
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_auth_kind }}"
service_account_file: "{{ gcp_service_account_file }}"
zone: "{{ gcp_zone }}"
machine_type: "{{ vm_machine_type | default('e2-standard-2') }}"
disks:
- auto_delete: true
boot: true
initialize_params:
disk_size_gb: "{{ vm_disk_size | default(20) }}"
source_image: "{{ gcp_source_image }}"
network_interfaces:
- network: "{{ network }}"
access_configs:
- name: External NAT
type: ONE_TO_ONE_NAT
labels: "{{ gcp_default_labels | combine(gcp_extra_labels) }}"
metadata: "{{ gcp_meta_data | default({}) }}"
register: instance_result

- set_fact:
instance_created: true
when: instance_result is defined and instance_result.changed
rescue:
- name: Remove failed GCP compute instance
google.cloud.gcp_compute_instance:
name: "{{ vm_name }}"
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_auth_kind }}"
service_account_file: "{{ gcp_service_account_file }}"
zone: "{{ gcp_zone }}"
state: absent
when: not instance_created
32 changes: 7 additions & 25 deletions ansible/roles/create-vm/tasks/create-gcp-vm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,27 +50,13 @@
state: present
register: network


- set_fact:
instance_created: false

- name: Create GCP VM
google.cloud.gcp_compute_instance:
name: "{{ vm_name }}"
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_auth_kind }}"
service_account_file: "{{ gcp_service_account_file }}"
zone: "{{ gcp_zone }}"
machine_type: "{{ vm_machine_type | default('e2-standard-2') }}"
disks:
- auto_delete: true
boot: true
initialize_params:
disk_size_gb: "{{ vm_disk_size | default(20) }}"
source_image: "{{ gcp_source_image }}"
network_interfaces:
- network: "{{ network }}"
access_configs:
- name: External NAT
type: ONE_TO_ONE_NAT
labels: "{{ gcp_default_labels | combine(gcp_extra_labels) }}"
metadata: "{{ gcp_meta_data | default({}) }}"
ansible.builtin.include_tasks:
file: create-gcp-instance.yml

# This looks like a lot, and its mostly because ansible support
# for "breaking" from a loop is not all that great at the moment.
Expand All @@ -80,9 +66,5 @@
loop: "{{ vm_available_zones }}"
loop_control:
loop_var: gcp_zone
register: instance_result
when: >
(vm_arch == "amd64" or vm_arch == "arm64") and not condition and excluded == false
vars:
condition: "{{ (instance_result | default({'changed': false})).changed }}"

(vm_arch == "amd64" or vm_arch == "arm64") and excluded == false
Loading