-
Notifications
You must be signed in to change notification settings - Fork 85
/
Copy pathdeploy-gcp-instances.yml
27 lines (24 loc) · 1005 Bytes
/
deploy-gcp-instances.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
- name: Create instance(s)
hosts: localhost
connection: local
gather_facts: no
tasks:
- name: Launch instances
gce:
instance_names: "{{ item }}"
machine_type: "{{ machine_type }}"
image: "{{ image }}"
service_account_email: "{{ service_account_email }}"
credentials_file: "{{ credentials_file }}"
project_id: "{{ project_id }}"
register: gce
with_items: "{{ instance_list }}"
- name: Wait for SSH to come up
wait_for: host={{ item.public_ip }} port=22 delay=10 timeout=60
with_items: "{{ gce.results[0].instance_data }}"
- name: Add host to web servers
add_host: hostname={{ item.public_ip }} private_ip={{ item.private_ip }} groupname=web_servers
with_items: "{{ gce.results[0].instance_data }}"
- name: Add host to db servers
add_host: hostname={{ item.public_ip }} private_ip={{ item.private_ip }} groupname=db_servers
with_items: "{{ gce.results[1].instance_data }}"