-
Notifications
You must be signed in to change notification settings - Fork 1
/
provision-nfs.yml
187 lines (157 loc) · 5.45 KB
/
provision-nfs.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
- 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
service_account_email: [email protected]
credentials_file: /etc/ansible/keys/service-key.json
project_id: paris-code
tasks:
- name: Launch instances
gce:
instance_names: nfs
machine_type: "{{ machine_type }}"
image: "{{ image }}"
service_account_email: "{{ service_account_email }}"
credentials_file: "{{ credentials_file }}"
project_id: "{{ project_id }}"
tags: nfs
register: gce
- name: Create log disks
gce_pd:
name: "{{ item.name }}-log"
instance_name: "{{ item.name }}"
mode: READ_WRITE
size_gb: 10
service_account_email: "{{ service_account_email }}"
credentials_file: "{{ credentials_file }}"
project_id: "{{ project_id }}"
zone: "{{ item.zone }}"
with_items: "{{ gce.instance_data }}"
- name: Create data disks
gce_pd:
name: "{{ item.name }}-data"
instance_name: "{{ item.name }}"
mode: READ_WRITE
size_gb: 100
disk_type: pd-ssd
service_account_email: "{{ service_account_email }}"
credentials_file: "{{ credentials_file }}"
project_id: "{{ project_id }}"
zone: "{{ item.zone }}"
with_items: "{{ gce.instance_data }}"
- name: Create backup disk
gce_pd:
name: "{{ item.name }}-backup"
instance_name: "{{ item.name }}"
mode: READ_WRITE
size_gb: 200
service_account_email: "{{ service_account_email }}"
credentials_file: "{{ credentials_file }}"
project_id: "{{ project_id }}"
zone: "{{ item.zone }}"
with_items: "{{ gce.instance_data }}"
- 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.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
opts="-E lazy_itable_init=0,lazy_journal_init=0,discard"
- name: Set up filesystem for data disks
filesystem: >
fstype=ext4
dev=/dev/disk/by-id/google-{{ ansible_hostname }}-data
opts="-b size=512 -N 10000000 -E lazy_itable_init=0,lazy_journal_init=0,discard"
- name: Set up filesystem for backup disks
filesystem: >
fstype=ext4
dev=/dev/disk/by-id/google-{{ ansible_hostname }}-backup
opts="-b size=512 -N 20000000 -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
state=mounted
notify: restart rsyslog
- name: Mount data disks
mount: >
name=/data
fstype=ext4
src=/dev/disk/by-id/google-{{ ansible_hostname }}-data
state=mounted
- name: Set up file permissions
file: path=/data owner=www-data group=www-data state=directory
- name: Set up subdirectories
file: >
path=/mnt/datadisk/{{ item }}
state=directory mode=755 owner=www-data group=www-data
with_items:
- cache
- data
- proxycache
- name: Mount backup disks
mount: >
name=/backup
fstype=ext4
src=/dev/disk/by-id/google-{{ ansible_hostname }}-backup
state=mounted
- name: Set up file permissions
file: path=/backup owner=www-data group=www-data state=directory
handlers:
- name: restart rsyslog
service: name=rsyslog state=restarted
- name: Set up nfs
hosts: launched
connection: ssh
gather_facts: no
become: yes
roles:
- role: geerlingguy.nfs
nfs_exports:
- /data *(rw,sync,no_subtree_check)
- /backup *(ro,sync,no_subtree_check)
- name: Disable mlocate
hosts: launched
connection: ssh
gather_facts: no
become: yes
tasks:
- name: Change permission of cron.daily mlocate to disable execution.
file: /etc/cron.daily/mlocate mode=a-x
- name: Set up rsnapshot
hosts: launched
connection: ssh
gather_facts: no
become: yes
tasks:
- name: Install rsnapshot
apt: name=rsnapshot state=latest
- name: Configure rsnapshot
copy: src=files/rsnapshot.conf dest=/etc/rsnapshot.conf
- name: Configure rsnapshot cron
copy: src=files/rsnapshot.cron dest=/etc/cron.d/rsnapshot