-
Notifications
You must be signed in to change notification settings - Fork 18
/
provision-dev-env-container-templates.yml
293 lines (288 loc) · 7.44 KB
/
provision-dev-env-container-templates.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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
- name: Setup
become: yes
hosts: dev
tasks:
- name: Random number to avoid collisions
set_fact:
uuid: '{{ 999999999999999 | random | to_uuid }}'
- name: Configure LXC to use a bridge
copy:
content: USE_LXC_BRIDGE="true"
dest: /etc/default/lxc-net
mode: 0774
- name: Start lxc-net service
service:
name: lxc-net
state: started
- name: Make /tmp/{{uuid}} dir
file:
state: directory
path: '/tmp/{{ uuid }}/lxc'
- name: Configure general container settings
copy:
content: |
lxc.net.0.type = veth
lxc.net.0.link = lxcbr0
lxc.net.0.flags = up
lxc.net.0.hwaddr = 00:16:3e:xx:xx:xx
dest: /etc/lxc/default.conf
mode: 0774
- name: Output Directories Vars
set_fact:
packer_output: '/tmp/{{ uuid }}/output'
template_output: '/tmp/{{ uuid }}/templates'
- name: Ensure Output Dirs
file:
path: '{{ item }}'
state: directory
loop:
- '{{ packer_output }}'
- '{{ template_output }}'
- name: Install depenendencies
apt:
name:
- python3-pip
- git
- lxc-pve-dev
- pkg-config
- dnsmasq
- cloud-guest-utils
- name: Grow sda3
command: growpart /dev/sda 3
ignore_errors: yes
- name: Resize sda3
command: pvresize /dev/sda3
ignore_errors: yes
- name: Resize root partition
command: lvresize -l +100%FREE /dev/pve/root
ignore_errors: yes
- name: Resize root fs
command: resize2fs /dev/mapper/pve-root
ignore_errors: yes
- name: Disable dnsmasq
systemd:
name: dnsmasq
enabled: no
state: stopped
- name: python3 lxc bindings
pip:
name: git+https://github.com/lxc/python3-lxc
executable: pip3
- name: python3 ansible
pip:
name: ansible
executable: pip3
- name: Restart lxc-net
systemd:
name: lxc-net
state: restarted
roles:
- packer
tags:
- always
- name: Delegate to Dev VM
become: yes
hosts: dev
tasks:
- name: Copy provisioning files
copy:
src: ./lxc/
dest: '/tmp/{{ uuid }}/lxc/'
tags:
- always
# Additional base templates can be found here http://uk.images.linuxcontainers.org
- name: Templates
hosts: dev
become: yes
tasks:
- name: Ghost CMS Ubuntu
command:
cmd: >
packer build
-var "name={{ name }}"
-var "dist={{ dist }}"
-var "rel={{ rel }}"
-var "playbook={{ playbook }}"
-var "packer_output={{ packer_output }}"
-var "uuid={{ uuid }}"
/tmp/{{ uuid }}/lxc/packer.json
vars:
name: ghostcms
dist: ubuntu
rel: focal
playbook: ghostcms-ubuntu
tags:
- ghostcms-ubuntu
- name: nginx Ubuntu
command:
cmd: >
packer build
-var "name={{ name }}"
-var "dist={{ dist }}"
-var "rel={{ rel }}"
-var "playbook={{ playbook }}"
-var "packer_output={{ packer_output }}"
-var "uuid={{ uuid }}"
/tmp/{{ uuid }}/lxc/packer.json
vars:
name: nginx
dist: ubuntu
rel: focal
playbook: nginx-ubuntu
tags:
- nginx-ubuntu
- name: MEAN Ubuntu
command:
cmd: >
packer build
-var "name={{ name }}"
-var "dist={{ dist }}"
-var "rel={{ rel }}"
-var "playbook={{ playbook }}"
-var "packer_output={{ packer_output }}"
-var "uuid={{ uuid }}"
/tmp/{{ uuid }}/lxc/packer.json
vars:
name: mean
dist: ubuntu
rel: focal
playbook: mean-ubuntu
tags:
- mean-ubuntu
- name: Game Servers Ubuntu
command:
cmd: >
packer build
-var "name={{ name }}"
-var "dist={{ dist }}"
-var "rel={{ rel }}"
-var "playbook={{ playbook }}"
-var "packer_output={{ packer_output }}"
-var "uuid={{ uuid }}"
/tmp/{{ uuid }}/lxc/packer.json
vars:
name: gameservers
dist: ubuntu
rel: focal
playbook: linuxgsm-ubuntu
tags:
- linuxgsm-ubuntu
- name: Devtools Ubuntu
command:
cmd: >
packer build
-var "name={{ name }}"
-var "dist={{ dist }}"
-var "rel={{ rel }}"
-var "playbook={{ playbook }}"
-var "packer_output={{ packer_output }}"
-var "uuid={{ uuid }}"
/tmp/{{ uuid }}/lxc/packer.json
vars:
name: devtools
dist: ubuntu
rel: focal
playbook: devtools-ubuntu
tags:
- devtools-ubuntu
- name: LEMP Ubuntu
command:
cmd: >
packer build
-var "name={{ name }}"
-var "dist={{ dist }}"
-var "rel={{ rel }}"
-var "playbook={{ playbook }}"
-var "packer_output={{ packer_output }}"
-var "uuid={{ uuid }}"
/tmp/{{ uuid }}/lxc/packer.json
vars:
name: lemp
dist: ubuntu
rel: focal
playbook: lemp-ubuntu
tags:
- lemp-ubuntu
- name: Wordpress Ubuntu
command:
cmd: >
packer build
-var "name={{ name }}"
-var "dist={{ dist }}"
-var "rel={{ rel }}"
-var "playbook={{ playbook }}"
-var "packer_output={{ packer_output }}"
-var "uuid={{ uuid }}"
/tmp/{{ uuid }}/lxc/packer.json
vars:
name: wordpress
dist: ubuntu
rel: focal
playbook: wordpress-ubuntu
tags:
- wordpress-ubuntu
- name: Node Ubuntu
command:
cmd: >
packer build
-var "name={{ name }}"
-var "dist={{ dist }}"
-var "rel={{ rel }}"
-var "playbook={{ playbook }}"
-var "packer_output={{ packer_output }}"
-var "uuid={{ uuid }}"
/tmp/{{ uuid }}/lxc/packer.json
vars:
name: node
dist: ubuntu
rel: focal
playbook: node-ubuntu
tags:
- node-ubuntu
# Packer exports containers as rootfs.tar.gz with the following structure
# rootfs/
# - bin
# - boot
# - etc...
# Proxmox expects bin,boot,etc... without parent rootfs dir
# As such we must extract rootfs and then compress just its contents
- name: Fix Archives
become: yes
hosts: dev
tasks:
- name: Get all templates
find:
pattern: 'rootfs.tar.gz'
path: '{{ packer_output }}'
recurse: yes
register: files
- name: Extract
shell:
cmd: 'tar --preserve-permissions --numeric-owner -xzf {{ item.path }} -C {{ item.path | dirname }}'
warn: false
loop: '{{ files.files }}'
- name: Compress
shell:
cmd: "tar -czf {{ template_output }}/netsoc-{{ item.path.split('/')[-2] }}.tar.gz -C {{ item.path | dirname }}/rootfs ."
warn: false
loop: '{{ files.files }}'
tags:
- always
- name: Copy Templates to Proxmox
become: yes
hosts: dev
tasks:
- name: Copy templates
command: 'mv {{ template_output }}/* /var/lib/vz/template/cache/'
tags:
- always
- name: Cleanup
become: yes
hosts: dev
tasks:
- name: Tidy up directory
file:
path: '/tmp/{{ uuid }}'
state: absent
tags:
- always