-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathprovision-ants.yml
More file actions
378 lines (305 loc) · 10.2 KB
/
provision-ants.yml
File metadata and controls
378 lines (305 loc) · 10.2 KB
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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
---
- name: SYSTEM TWEAKS
hosts: all
tags: system_tweaks
vars:
- ansible_python_interpreter: /usr/bin/python3
- ansible_local: "/home/vagrant/.ansible"
- python3_local: "/home/vagrant/.local/lib/python3.11/site-packages"
tasks:
- name: CREATE FOLDERS
file:
path: "{{ item }}"
state: directory
loop:
- "{{ ansible_local }}/plugins/modules"
- "{{ ansible_local }}/plugins/filter"
- "{{ ansible_local }}/plugins/action"
- "{{ ansible_local }}/roles"
- name: SUPPRESS UBUNTU MOTD & LASTLOGIN
become: true
shell: |
chmod a-x /etc/update-motd.d/*
echo "PrintLastLog no" >> /etc/ssh/sshd_config
systemctl reload ssh.service
- name: SET HOSTNAME
become: true
hostname:
name: ants
- name: FIX LOCAL HOSTNAME RESOLUTION
become: true
shell: "sed -i 's/bookworm/ants/g' /etc/hosts"
- name: CREATE /ANTS
become: true
file:
path: /ants
state: directory
mode: 0755
owner: vagrant
group: vagrant
- name: COPY VARIOUS FILES FOR ROOT AND VAGRANT
become: true
copy:
src: "{{ item.src }}"
dest: "{{ item.dest }}"
owner: "{{ item.owner }}"
group: "{{ item.group }}"
mode: "{{ item.mode }}"
backup: true
loop:
- {src: 'files/motd', dest: '/etc/motd',
owner: root, group: root, mode: 644}
- {src: 'files/bash.sh', dest: '/root/.bash.sh',
owner: root, group: root, mode: 644}
- {src: 'files/dir_colors', dest: '/root/.dir_colors',
owner: root, group: root, mode: 644}
- {src: 'files/vim/vimrc', dest: '/root/.vimrc',
owner: root, group: root, mode: 644}
- {src: 'files/vim/', dest: '/root/.vim',
owner: root, group: root, mode: preserve}
- {src: 'files/bash.sh', dest: '/home/vagrant/.bash.sh',
owner: vagrant, group: vagrant, mode: 644}
- {src: 'files/dir_colors', dest: '/home/vagrant/.dir_colors',
owner: vagrant, group: vagrant, mode: 644}
- {src: 'files/vim/vimrc', dest: '/home/vagrant/.vimrc',
owner: vagrant, group: vagrant, mode: 644}
- {src: 'files/vim/', dest: '/home/vagrant/.vim',
owner: vagrant, group: vagrant, mode: preserve}
- {src: 'files/.gitconfig', dest: '/home/vagrant/.gitconfig',
owner: vagrant, group: vagrant, mode: preserve}
- name: BASHRC FOR USER - VAGRANT
lineinfile:
path: /home/vagrant/.bashrc
insertafter: EOF
line: source /home/vagrant/.bash.sh
- name: BASHRC FOR USER - ROOT
become: true
lineinfile:
path: /root/.bashrc
insertafter: EOF
line: source /root/.bash.sh
- name: INSTALL SYSTEM PACKAGES
hosts: all
tags: install_system
vars_files:
- ants.yml
vars:
- apt_list: "{{ ants | json_query(
'package_groups[].packages[?installed_by==`apt`][].name')
}}"
- ansible_python_interpreter: /usr/bin/python3
- ansible_local: "/home/vagrant/.ansible"
- python3_local: "/home/vagrant/.local/lib/python3.11/site-packages"
tasks:
- name: UPDATE SYSTEM PACKAGES
become: true
apt:
update_cache: true
cache_valid_time: 3600
upgrade: dist
- debug:
msg: "Installing via apt: {{ apt_list }}"
- name: INSTALL PACKAGES VIA APT
become: true
apt:
name: "{{ apt_list }}"
state: latest
install_recommends: false
# - name: INSTALL PYTHON PACKAGES
# hosts: all
# tags: install_pip
# vars_files:
# - ants.yml
# vars:
# - pip3_list: "{{ ants | json_query(
# 'package_groups[].packages[?installed_by==`pip3`][]')
# }}"
# - ansible_python_interpreter: /usr/bin/python3
# - ansible_local: "/home/vagrant/.ansible"
# - python3_local: "/home/vagrant/.local/lib/python3.11/site-packages"
# tasks:
# - debug:
# msg: "Installing via pip3: {{ pip3_list | json_query('[].name') }}"
# - name: GENERATE REQUIREMENTS.TXT
# template:
# src: files/requirements.j2
# dest: /vagrant/requirements.txt
# - name: INSTALL PYTHON3 PACKAGES VIA PIP3
# pip:
# requirements: "/vagrant/requirements.txt"
# extra_args: --user -U
# executable: pip3
# - name: VALIDATE ALL PIP3 DEPENDENCIES ARE IN ORDER
# shell: pip3 check
- name: INSTALL DOCKER UTILS AND CONTAINERS
hosts: all
tags: install_containers
vars_files:
- ants.yml
vars:
- docker_image_list: "{{ ants | json_query(
'package_groups[].packages[?installed_by==`docker`][].name')
}}"
- docker_start_list: "{{ ants | json_query(
'package_groups[].packages[?installed_by==`docker` &&
autostart][]')
}}"
- ansible_python_interpreter: /usr/bin/python3
- ansible_local: "/home/vagrant/.ansible"
- python3_local: "/home/vagrant/.local/lib/python3.11/site-packages"
- DOCKER_COMPOSE_VERSION: "{{ ants | json_query(
'package_groups[].packages[?name==`docker-compose`][].version')
| first
}}"
tasks:
# - debug:
# msg: "Fetching docker images: {{ docker_image_list }}"
# - name: PULL DOCKER IMAGES LOCALLY
# docker_image:
# name: "{{ item }}"
# tag: latest
# loop: "{{ docker_image_list | list }}"
# - debug:
# msg: "Starting docker containers: {{ docker_start_list }}"
# - name: START DOCKER CONTAINERS
# docker_container:
# name: "{{ item | replace('/', '_') }}"
# image: "{{ item.name }}:{{ item.version }}:"
# published_ports: "{{ item.host_port }}:{{ item.container_port }}"
# loop: "{{ docker_start_list | list }}"
- name: CREATE SYMLINK FOR DOCKER-COMPOSE
become: true
file:
src: "/usr/libexec/docker/cli-plugins/docker-compose"
dest: "/usr/local/bin/docker-compose"
state: "link"
- name: INSTALL CONTAINER-LAB
hosts: all
tags: install_container_lab
vars:
CONTAINERLAB_VERSION: "0.56.0"
CONTAINERLAB_CHECKSUM: "sha256:bed9958800a5c65c78a80f8392c3965e9c27c5d054316a7500d39502347a4172"
tasks:
- name: DOWNLOAD CONTAINERLAB DEB {{ CONTAINERLAB_VERSION }}
become: true
get_url:
url: "https://github.com/srl-labs/containerlab/releases/download/\
v{{ CONTAINERLAB_VERSION }}/\
containerlab_{{ CONTAINERLAB_VERSION }}_linux_amd64.deb"
dest: "/tmp/containerlab.deb"
mode: "644"
checksum: "{{ CONTAINERLAB_CHECKSUM }}"
- name: INSTALL CONTAINERLAB {{ CONTAINERLAB_VERSION }}
become: true
shell: |
dpkg -i /tmp/containerlab.deb
rm /tmp/containerlab.deb
- name: INSTALL VALE
hosts: all
tags: install_vale
vars:
VALE_VERSION: "3.7.0"
VALE_CHECKSUM: "sha256:1fe152f95b38d61be2ec914c5dd816e8733e5bbe78bb6e9827a1214e4b711109"
tasks:
- name: DOWNLOAD CONTAINERLAB DEB {{ CONTAINERLAB_VERSION }}
become: true
get_url:
url: "https://github.com/errata-ai/vale/releases/download/\
v{{ VALE_VERSION }}/\
vale_{{ VALE_VERSION }}_Linux_64-bit.tar.gz"
dest: "/tmp/vale.tar.gz"
mode: "644"
checksum: "{{ VALE_CHECKSUM }}"
- name: INSTALL VALE {{ VALE_VERSION }}
become: true
shell: |
cd /usr/local/bin/
tar -xzf /tmp/vale.tar.gz
rm LICENSE README.md
rm /tmp/vale.tar.gz
- name: INSTALL HASHICORP TOOLS
hosts: all
tags: install_hashicorp
tasks:
- name: ADD HASHICORP APT SIGNING KEY
become: true
ansible.builtin.apt_key:
url: "https://apt.releases.hashicorp.com/gpg"
state: present
- name: ADD HASHICORP APT REPOSITORY
become: true
ansible.builtin.apt_repository:
repo: "deb [arch=amd64] https://apt.releases.hashicorp.com bookworm main"
state: present
- name: INSTALL PACKAGES VIA APT
become: true
apt:
name:
- packer
- terraform
state: latest
install_recommends: false
- name: INSTALL GOLANG
hosts: all
tags: install_golang
vars:
GOLANG_VERSION: "1.22.6"
tasks:
- name:
become: true
ansible.builtin.shell: |
curl -sL -o /tmp/go.tar.gz "https://go.dev/dl/go{{ GOLANG_VERSION }}.linux-amd64.tar.gz"
rm -rf /usr/local/go && tar -C /usr/local -xzf /tmp/go.tar.gz
rm /tmp/go.tar.gz
- name: INSTALL POETRY
hosts: all
tags: install_poetry
vars:
POETRY_VERSION: "1.8.3"
tasks:
- name:
ansible.builtin.shell: |
pipx install poetry=={{ POETRY_VERSION }}
/home/vagrant/.local/bin/poetry completions bash >> ~/.bash_completion
- name: INSTALL PYENV
hosts: all
tags: install_pyenv
vars:
PYENV_VERSION: "2.4.10"
tasks:
- name:
ansible.builtin.shell: |
export PYENV_GIT_TAG=v{{ PYENV_VERSION }}
curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash
- name: INSTALL OTHER PACKAGES
hosts: all
tags: install_other
vars_files:
- ants.yml
vars:
- git_clone_list: "{{ ants | json_query(
'package_groups[].packages[?installed_by==`git`][]')
}}"
- ansible_galaxy_list: "{{ ants | json_query(
'package_groups[].packages[?installed_by==`ansible-galaxy`][]')
}}"
- ansible_python_interpreter: /usr/bin/python3
- ansible_local: "/home/vagrant/.ansible"
- python3_local: "/home/vagrant/.local/lib/python3.11/site-packages"
tasks:
- debug:
msg: "Cloning via git: {{ git_clone_list | json_query('[].name') }}"
- name: CLONE GIT REPOSITORIES
git:
repo: "{{ item.url }}"
dest: "{{ item.dest }}"
recursive: true
force: true
depth: 1
loop: "{{ git_clone_list | list }}"
- debug:
msg: "Ansible Galaxy Collections: {{ ansible_galaxy_list |
json_query('[].name') }}"
- name: INSTALL ANSIBLE GALAXY ROLES
command: "ansible-galaxy collection install {{ item.name }}"
loop: "{{ ansible_galaxy_list | list }}"