diff --git a/sheetstorm-deployment/create-compute-instance-for-sheetstorm.yml b/sheetstorm-deployment/create-compute-instance-for-sheetstorm.yml new file mode 100644 index 000000000..9078e5f6a --- /dev/null +++ b/sheetstorm-deployment/create-compute-instance-for-sheetstorm.yml @@ -0,0 +1,19 @@ +- hosts: + - localhost + vars_files: + - ../../sheetstorm-config/var.yml + vars: + server_name: sheetstorm + name_of_ip: "{{ server_name }}" + roles: + - reserve_static_ip + tasks: + - block: + - name: Create a GCP instance for {{ server_name }} + command: > + gcloud compute instances create {{ server_name }} + --description "Vm instance that contain {{ server_name }}" + --machine-type {{ machine_type }} + --address {{ name_of_ip }} + --project {{ gke.project }} + --zone {{ gke.zone }} diff --git a/sheetstorm-deployment/roles/reserve_static_ip/tasks/main.yml b/sheetstorm-deployment/roles/reserve_static_ip/tasks/main.yml new file mode 100644 index 000000000..adbe13b54 --- /dev/null +++ b/sheetstorm-deployment/roles/reserve_static_ip/tasks/main.yml @@ -0,0 +1,15 @@ +- name: Check if static IP address already exists + shell: > + gcloud compute addresses list + --project {{ gke.project }} + | grep {{ name_of_ip }} + register: ip_address_result + ignore_errors: yes + +- name: Reserve static IP address for the "{{ server_name }}" instance + command: > + gcloud compute addresses create {{ name_of_ip }} + --description "Static IP attached to {{ server_name }} instance" + --project {{ gke.project }} + --region {{ gke.region }} + when: ip_address_result.stdout == ""