-
Notifications
You must be signed in to change notification settings - Fork 1
/
provision-web.yml
122 lines (103 loc) · 3.92 KB
/
provision-web.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
- name: Create instance(s)
hosts: localhost
gather_facts: no
connection: local
vars:
machine_type: n1-standard-1 # default
image: https://www.googleapis.com/compute/v1/projects/ubuntu-os-cloud/global/images/ubuntu-1604-xenial-v20170330
next_image: https://www.googleapis.com/compute/v1/projects/ubuntu-os-cloud/global/images/ubuntu-1804-bionic-v20190722a
service_account_email: [email protected]
credentials_file: /etc/ansible/keys/service-key.json
project_id: paris-code
tasks:
- name: Launch instances
gce:
instance_names: web1,web2
machine_type: "{{ machine_type }}"
image: "{{ image }}"
service_account_email: "{{ service_account_email }}"
credentials_file: "{{ credentials_file }}"
project_id: "{{ project_id }}"
tags: webserver,http-server,https-server
register: gce
- name: Create log disks
gce_pd:
name: "{{ item.name }}-log-1"
instance_name: "{{ item.name }}"
mode: READ_WRITE
size_gb: 20
service_account_email: "{{ service_account_email }}"
credentials_file: "{{ credentials_file }}"
project_id: "{{ project_id }}"
zone: "{{ item.zone }}"
with_items: "{{ gce.instance_data }}"
- name: Assemble qualified instance names
shell: echo {{ item.zone }}/{{ item.name }}
with_items: "{{ gce.instance_data }}"
register: qnames
- name: Create load balancing rule
gce_lb:
name: lb
external_ip: pencilcode-ip
region: us-central1
members: "{{ qnames.results|map(attribute='stdout')|list }}"
httphealthcheck_name: lb-check
httphealthcheck_host: pencil.io
httphealthcheck_port: 80
httphealthcheck_path: "/load/first"
service_account_email: "{{ service_account_email }}"
credentials_file: "{{ credentials_file }}"
project_id: "{{ project_id }}"
- name: Wait for SSH to come up
wait_for: host={{ item.private_ip }} port=22 delay=5 timeout=60
with_items: "{{ gce.instance_data }}"
- name: Add host to groupname
add_host: hostname={{ item.private_ip }} groupname=launched
with_items: "{{ gce.instance_data }}"
- name: reset known-hosts for ips
command: ssh-keygen -R {{ item.public_ip }}
with_items: "{{ gce.instance_data }}"
- name: registering new known-host for ips
shell: ssh-keyscan -H {{ item.public_ip }} >> ~/.ssh/known_hosts
with_items: "{{ gce.instance_data }}"
- name: reset known-hosts for ips
command: ssh-keygen -R {{ item.private_ip }}
with_items: "{{ gce.instance_data }}"
- name: registering new known-host for ips
shell: ssh-keyscan -H {{ item.private_ip }} >> ~/.ssh/known_hosts
with_items: "{{ gce.instance_data }}"
- name: reset known-hosts for names
command: ssh-keygen -R {{ item.name }}
with_items: "{{ gce.instance_data }}"
- name: registering new known-host for names
shell: ssh-keyscan -H {{ item.name }} >> ~/.ssh/known_hosts
with_items: "{{ gce.instance_data }}"
- name: Set up disks
hosts: launched
connection: ssh
become: yes
tasks:
- name: Set up filesystem for log disks
filesystem: >
fstype=ext4
dev=/dev/disk/by-id/google-{{ ansible_hostname }}-log-1
opts="-E lazy_itable_init=0,lazy_journal_init=0,discard"
- name: Mount log disks
mount: >
name=/var/log
fstype=ext4
src=/dev/disk/by-id/google-{{ ansible_hostname }}-log-1
state=mounted
notify: restart rsyslog
- name: install nfs client
apt: pkg=nfs-common state=present
- name: Mount data disk
mount: >
name=/mnt/datadisk
fstype=nfs
src=nfs:/data
opts=rw,sync,nfsvers=3
state=mounted
handlers:
- name: restart rsyslog
service: name=rsyslog state=restarted