SHARE
TWEET

Untitled

a guest May 26th, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. - name: Create an instance
  2.   hosts: localhost
  3.   gather_facts: no
  4.   vars:
  5.       gcp_project: my-project
  6.       gcp_cred_kind: serviceaccount
  7.       gcp_cred_file: /home/my_account.json
  8.       zone: "us-central1-a"
  9.       region: "us-central1"
  10.  
  11.   tasks:
  12.    - name: create a disk
  13.      gcp_compute_disk:
  14.          name: 'disk-instance'
  15.          size_gb: 50
  16.          source_image: 'projects/ubuntu-os-cloud/global/images/family/ubuntu-1604-lts'
  17.          zone: "{{ zone }}"
  18.          project: "{{ gcp_project }}"
  19.          auth_kind: "{{ gcp_cred_kind }}"
  20.          service_account_file: "{{ gcp_cred_file }}"
  21.          scopes:
  22.            - https://www.googleapis.com/auth/compute
  23.          state: present
  24.      register: disk
  25.    - name: create a network
  26.      gcp_compute_network:
  27.          name: 'network-instance'
  28.          project: "{{ gcp_project }}"
  29.          auth_kind: "{{ gcp_cred_kind }}"
  30.          service_account_file: "{{ gcp_cred_file }}"
  31.          scopes:
  32.            - https://www.googleapis.com/auth/compute
  33.          state: present
  34.      register: network
  35.    - name: create a address
  36.      gcp_compute_address:
  37.          name: 'address-instance'
  38.          region: "{{ region }}"
  39.          project: "{{ gcp_project }}"
  40.          auth_kind: "{{ gcp_cred_kind }}"
  41.          service_account_file: "{{ gcp_cred_file }}"
  42.          scopes:
  43.            - https://www.googleapis.com/auth/compute
  44.          state: present
  45.      register: address
  46.    - name: create a instance
  47.      gcp_compute_instance:
  48.          state: present
  49.          name: test-vm
  50.          machine_type: n1-standard-1
  51.          disks:
  52.            - auto_delete: true
  53.              boot: true
  54.              source: "{{ disk }}"
  55.          network_interfaces:
  56.              - network: "{{ network }}"
  57.                access_configs:
  58.                  - name: 'External NAT'
  59.                    nat_ip: "{{ address }}"
  60.                    type: 'ONE_TO_ONE_NAT'
  61.          zone: "{{ zone }}"
  62.          project: "{{ gcp_project }}"
  63.          auth_kind: "{{ gcp_cred_kind }}"
  64.          service_account_file: "{{ gcp_cred_file }}"
  65.          scopes:
  66.            - https://www.googleapis.com/auth/compute
  67.      register: instance
  68.  
  69.     - name: Wait for SSH to come up
  70.       wait_for: host={{ address.address }} port=22 delay=10 timeout=60
  71.  
  72.     - name: Add host to groupname
  73.       add_host: hostname={{ address.address }} groupname=new_instances
  74.  
  75.  
  76. - name: Manage new instances
  77.   hosts: new_instances
  78.   connection: ssh
  79.   sudo: True
  80.   roles:
  81.     - base_configuration
  82.     - production_server
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top