-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall.yaml
293 lines (251 loc) · 7.27 KB
/
install.yaml
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
# Note ensure python-netaddr or python3-netaddr is installed!
---
- name: Setup geproxy
gather_facts: true
hosts: all
vars_files:
- defaults.yaml
- config.yml
- config.yaml
become: yes
handlers:
- name: Restart systemd-resolved
ansible.builtin.service:
name: systemd-resolved
state: restarted
- name: Create mountpoint
become: no
ansible.builtin.file:
state: directory
path: /opt/geproxy/pxe/ubuntu
notify: Mount the ISO
- name: Mount the ISO
ansible.posix.mount:
path: /opt/geproxy/pxe/ubuntu
src: /opt/geproxy/pxe/ubuntu.iso
fstype: iso9660
opts: ro
state: mounted # Ensure that this is made permanent in /etc/fstab
tasks:
- name: Check if already installed
tags: never, clean
ansible.builtin.stat:
path: /opt/geproxy
register: geproxy
- name: Clean composition
tags: never, clean
ansible.builtin.command:
chdir: /opt/geproxy
cmd: docker compose down --rmi=local
when: geproxy.stat.exists
- name: Unmount Ubuntu
tags: never, clean
ansible.posix.mount:
path: /opt/geproxy/pxe/ubuntu
state: unmounted # Ensure that this is made permanent in /etc/fstab
- name: Remove files
tags: never, clean
become: yes
ansible.builtin.file:
path: /opt/geproxy
state: absent
when: geproxy.stat.exists
- name: Remove old packages
ansible.builtin.apt:
state: absent
name:
- docker
- docker-engine
- docker.io
- containerd
- runc
- name: Install dependencies
ansible.builtin.apt:
update_cache: yes
state: present
name:
- ca-certificates
- curl
- gnupg
- lsb-release
- lshw
- rsync
- pxelinux
- syslinux-common
- make
- binutils
- perl
- liblzma-dev
- python3-netaddr
- mtools
- gcc
- name: Add docker repo
block:
- name: Ensure key folder exists
ansible.builtin.file:
path: /etc/apt/keyrings
state: directory
- name: APT key
ansible.builtin.apt_key:
url: https://download.docker.com/linux/ubuntu/gpg
state: present
- name: APT source
ansible.builtin.apt_repository:
filename: docker
repo: "deb https://download.docker.com/linux/ubuntu {{ ansible_distribution_release }} stable"
state: present
- name: Install docker
ansible.builtin.apt:
state: present
name:
- docker-ce
- docker-ce-cli
- containerd.io
- docker-compose-plugin
- docker-compose
- name: Add user to docker group
user:
name: '{{ ansible_user }}'
groups: docker
append: yes
when: ansible_user != "root"
- name: Create geproxy directory and set permissions
tags: always
ansible.builtin.file:
path: /opt/geproxy
state: directory
owner: "{{ ansible_user }}"
mode: u=rwx,g=rx,o=rx
recurse: no
- name: Synchronize current directory
tags: always
become: no
synchronize:
src: ./
dest: /opt/geproxy/
owner: no
group: no
- name: Ensure `./acng/` exists
tags: always
ansible.builtin.file:
path: /opt/geproxy/acng
state: directory
- name: Fill .env
tags: always
become: no
ansible.builtin.template:
src: env.j2
dest: /opt/geproxy/.env
- name: Check if /etc/netplan/99-geproxy.yaml exists
ansible.builtin.stat:
path: /etc/netplan/99-geproxy.yaml
register: netplan
- name: Create netplan
block:
- name: Check which netplans to rename
ansible.builtin.find:
path: /etc/netplan
patterns: '*.yaml,*.yml'
register: cleanup
ignore_errors: true
- name: Rename old netplans
command: "mv '{{ item.path }}' '{{ item.path }}.pre-geproxy.old'"
with_items: "{{ cleanup.files }}"
ignore_errors: true
# Construct netplan by discovering public, and private interfaces
- name: Discover public interface
ansible.builtin.shell: ip r | awk '/^default/ {print $5}'
register: public_interface_cmd
- name: Set public interface
ansible.builtin.set_fact:
public_interface: "{{ public_interface_cmd.stdout }}"
- name: Discover interfaces
ansible.builtin.shell: "lshw -class network | grep 'logical name' | grep -o '[^ ]*$' | sort -h"
register: all_interfaces_cmd
- name: Set all_interfaces
ansible.builtin.set_fact:
all_interfaces: "{{ all_interfaces_cmd.stdout_lines }}"
- name: Set private interfaces
ansible.builtin.set_fact:
private_interfaces: "{{ all_interfaces | difference([public_interface]) }}"
- name: Construct netplan
ansible.builtin.template:
src: netplan.j2
dest: /etc/netplan/99-geproxy.yaml
mode: "500"
- name: Generate netplan
ansible.builtin.command: "netplan generate"
- name: Apply netplan
ansible.builtin.command: "netplan apply"
when: not netplan.stat.exists
- name: Disable DNSStubListener
ansible.builtin.lineinfile:
path: /etc/systemd/resolved.conf
state: present
regexp: '^DNSStubListener\s*=\s*yes'
line: DNSStubListener=no
notify:
- Restart systemd-resolved
- name: Download ubuntu
become: no
ansible.builtin.get_url:
url: https://releases.ubuntu.com/24.04/ubuntu-24.04-live-server-amd64.iso
dest: /opt/geproxy/pxe/ubuntu.iso
notify: Create mountpoint
- name: Check for submodule ipxe
tags: ipxe
become: no
ansible.builtin.stat:
path: /opt/geproxy/ipxe/src
register: ipxeFound
- name: Initialise submodule ipxe
tags: ipxe
become: no
ansible.builtin.command:
chdir: /opt/geproxy/
cmd: "git submodule update --init --recursive ipxe"
when: not ipxeFound.stat.exists
- name: "Clean iPXE files '{{ item }}'"
become: no
tags: never, ipxe
ansible.builtin.file:
path: '{{ item }}'
state: absent
with_items:
- /opt/geproxy/pxe/undionly.kpxe
- /opt/geproxy/ipxe/src/bin/undionly.kpxe
- /opt/geproxy/pxe/embed.ipxe
- name: Generate bootloader
tags: ipxe
become: no
block:
- name: Check for built bootloader
ansible.builtin.stat:
path: /opt/geproxy/pxe/undionly.kpxe
register: ipxeBuilt
- name: Generate bootloader script embed.ipxe
ansible.builtin.shell:
chdir: /opt/geproxy/pxe
cmd: |
set -a
source ../.env
set +a
envsubst '$PRIVATE_IP' < embed.ipxe.template > embed.ipxe
when: not ipxeBuilt.stat.exists
- name: Generate bootloader
ansible.builtin.command:
chdir: /opt/geproxy/ipxe/src
cmd: make clean bin/undionly.kpxe EMBED=/opt/geproxy/pxe/embed.ipxe
when: not ipxeBuilt.stat.exists
- name: Copy bootloader to location
ansible.builtin.copy:
src: /opt/geproxy/ipxe/src/bin/undionly.kpxe
dest: /opt/geproxy/pxe
remote_src: yes
when: not ipxeBuilt.stat.exists
- name: "Build the composition"
tags: start, restart
become: no
ansible.builtin.command:
chdir: /opt/geproxy
cmd: docker compose up -d --wait