Created
May 5, 2020 18:09
-
-
Save AlexMikhalev/498224bd5928f6b8bf96d2a6bdf2cd9f to your computer and use it in GitHub Desktop.
Correct ansible script to create GCE instance
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- name: 'Deploy gcp vm' | |
hosts: localhost | |
connection: local | |
become: false | |
gather_facts: no | |
vars: | |
gcp_project: "cord19kaggle" | |
gcp_cred_kind: "serviceaccount" | |
gcp_cred_file: "/home/alex/.config/.json" | |
gcp_region: "europe-west2" | |
gcp_zone: "europe-west2-c" | |
scopes: | |
- https://www.googleapis.com/auth/compute | |
# Roles & Tasks | |
tasks: | |
- name: create a disk | |
gcp_compute_disk: | |
name: disk-instance | |
size_gb: 50 | |
source_image: projects/ubuntu-os-cloud/global/images/family/ubuntu-1804-lts | |
zone: "{{ gcp_zone }}" | |
project: "{{ gcp_project }}" | |
auth_kind: "{{ gcp_cred_kind }}" | |
service_account_file: "{{ gcp_cred_file }}" | |
state: present | |
register: disk | |
- name: create a address | |
gcp_compute_address: | |
name: address-instance | |
region: "{{ gcp_region }}" | |
project: "{{ gcp_project }}" | |
auth_kind: "{{ gcp_cred_kind }}" | |
service_account_file: "{{ gcp_cred_file }}" | |
state: present | |
register: address | |
- name: create a instance | |
gcp_compute_instance: | |
name: gceinstance1 | |
project: "{{ gcp_project }}" | |
zone: "{{ gcp_zone }}" | |
machine_type: n1-standard-4 | |
disks: | |
- auto_delete: 'true' | |
boot: 'true' | |
source: "{{ disk }}" | |
labels: | |
environment: testing | |
network_interfaces: | |
- access_configs: | |
- name: External NAT | |
nat_ip: "{{ address }}" | |
type: ONE_TO_ONE_NAT | |
auth_kind: serviceaccount | |
service_account_file: "{{ gcp_cred_file }}" | |
scopes: "{{ scopes }}" | |
state: present | |
register: instance |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment