-
Notifications
You must be signed in to change notification settings - Fork 0
/
Taskfile.yaml
269 lines (251 loc) · 8.1 KB
/
Taskfile.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
---
version: 3
env:
limit: '{{ .limit | default "all" }}'
tasks:
pre-checks:
desc: Check the environment before running
internal: true
silent: true
run: once
cmds:
- cmd: |-
test -x "$(which python 2>/dev/null)" \
|| (echo "Cannot find 'python'. Please install before trying again."; exit 1)
- cmd: |-
test -x "$(which pip 2>/dev/null)" \
|| (echo "Cannot find 'pip'. Please install before trying again."; exit 1)
- cmd: |-
test -x "$(which pre-commit 2>/dev/null)" \
|| (echo "Cannot find 'pre-commit'. Please install before trying again."; exit 1)
- cmd: |-
test -x "$(which ansible 2>/dev/null)" \
|| (echo "Cannot find 'ansible'. Please install before trying again."; exit 1)
- cmd: |-
test -x "$(which ansible-playbook 2>/dev/null)" \
|| (echo "Cannot find 'ansible-playbook'. Please install before trying again."; exit 1)
- cmd: |-
test -x "$(which sshpass 2>/dev/null)" \
|| (echo "Cannot find 'sshpass'. Please install before trying again."; exit 1)
status:
# Setting this file will bypass pre-checks (only use if you are sure)
- test -f .skip-pre-checks
deps:
desc: Install the required dependencies for the repository
cmds:
- task: pre-commit
pre-commit:
desc: Add the `pre-commit` hook to this repository
deps:
- task: pre-checks
cmds:
- cmd: pre-commit install
generates:
- .git/hooks/pre-commit
rename:
desc: Find and rename all .yml files to .yaml
sources:
- "plays/*.yml"
- "plays/host_vars/*.yml"
- "plays/group_vars/*.yml"
- "roles/*/*/*.yml"
silent: true
cmds:
- cmd: |-
find -type f -iname '*.yml' | while read file
do
echo "${file#\./} -> $(basename $file .yml).yaml"
git mv -f $file ${file%.yml}.yaml 2>/dev/null \
|| mv -f $file ${file%.yml}.yaml
done
lint:
desc: Run linting tools against the Ansible files
summary: |
Run linting tools against the Ansible files inside this repository for
validity and correctness.
run: once
deps:
- task: pre-checks
- task: rename
sources:
- ".yamllint.yaml"
- "plays/*.yaml"
- "plays/host_vars/*.yaml"
- "plays/group_vars/*.yaml"
- "roles/*/*/*.yaml"
cmds:
- cmd: yamllint --config-file .yamllint.yaml plays/ roles/
- cmd: ansible-lint -c .config/ansible-lint.yaml
ping:
desc: Attempt to ping all nodes through Ansible
silent: true
cmds:
- cmd: |-
echo -e "Keys:\n" \
" \033[32m OK \033[34m DNS\n" \
" \033[33m No Route \033[33m Timeout\n" \
" \033[31m Refused) \033[31m Denied" \
"\033[0m"
echo
echo "Pinging all known hosts in the inventory to test for access..."
- cmd: |-
ansible \
--inventory inventory.yaml \
--forks 75 \
--ask-become-pass \
--module-name ansible.builtin.ping \
--one-line {{ .limit }} \
| awk '
/SUCCESS/ { printf "\033[32m %s\033[0m\n", $1 }
/Could not resolve hostname/ { printf "\033[34m %s\033[0m\n", $1 }
/No route to host/ { printf "\033[33m %s\033[0m\n", $1 }
/Connection refused/ { printf "\033[31m %s\033[0m\n", $1 }
/Connection timed out/ { printf "\033[33m %s\033[0m\n", $1 }
/Permanently added/ { node=$1 }
/Permission denied/ { printf "\033[31m %s\033[0m\n", node }
'
bootstrap:
desc: Bootstrap new servers using the bootstrap Ansible Play
silent: true
cmds:
- cmd: |-
ansible-playbook \
--syntax-check plays/bootstrap.yaml
- cmd: |-
ansible-playbook \
--user root \
--ask-pass plays/bootstrap.yaml \
--extra-vars bootstrap_chroot_dir=/mnt \
--force-handlers \
--limit {{ .limit }} \
--forks 10
# Remove any cached facts after running a bootstrap as the configuration
# of the host will change significantly, and a baseline needs a refresh
- cmd: rm -rf .cache
update:
desc: Update the pacman package databases on systems
silent: true
cmds:
- cmd: |-
ansible-playbook \
--syntax-check plays/update.yaml
- cmd: |-
ansible-playbook \
--ask-become-pass plays/update.yaml \
--force-handlers \
--limit {{ .limit }} \
--forks 10
upgrade:
desc: Update and upgrade the packages on systems
silent: true
cmds:
- cmd: |-
ansible-playbook \
--syntax-check plays/upgrade.yaml
- cmd: |-
ansible-playbook \
--ask-become-pass plays/upgrade.yaml \
--force-handlers \
--limit {{ .limit }} \
--forks 10
reboot:
desc: Update and upgrade the packages on systems
silent: true
cmds:
- cmd: |-
echo "This command will initiate a sequential reboot of the following hosts:"
ansible --inventory inventory.yaml --list-hosts {{ .limit }} | grep -v '\s\+hosts' | sort
read -p "Are you sure? (y/n) " -r
echo # Force a new line
if [[ ! ${REPLY} =~ ^[Yy] ]]; then
exit 1
fi
- cmd: |-
ansible \
--inventory inventory.yaml \
--forks 1 \
--ask-become-pass \
--module-name ansible.builtin.reboot \
--one-line {{ .limit }}
baseline:
desc: Baseline servers using the baseline Ansible Play
silent: true
cmds:
- cmd: |-
ansible-playbook \
--syntax-check plays/baseline.yaml
- cmd: |-
ansible-playbook \
--ask-become-pass plays/baseline.yaml \
--force-handlers \
--limit {{ .limit }} \
--forks 10
users:
desc: Update the users and sudo configuration on servers using the users Ansible Play
silent: true
cmds:
- cmd: |-
ansible-playbook \
--syntax-check plays/users.yaml
- cmd: |-
ansible-playbook \
--ask-become-pass plays/users.yaml \
--limit {{ .limit }} \
--forks 10
libvirtd:
desc: Configure libvirtd and deploy Virtual Machines
silent: true
cmds:
- cmd: |-
ansible-playbook \
--syntax-check plays/libvirtd.yaml
- cmd: |-
ansible-playbook \
--ask-become-pass plays/libvirtd.yaml \
--limit {{ .limit }} \
--forks 10
kubernetes:
desc: Deploy configurations for Kubernetes clusters
silent: true
cmds:
- cmd: |-
ansible-playbook \
--syntax-check plays/kubernetes.yaml
- cmd: |-
ansible-playbook \
--ask-become-pass plays/kubernetes.yaml \
--limit {{ .limit }} \
--forks 3
cache:
desc: Deploy configurations for caching proxy
silent: true
cmds:
- cmd: |-
ansible-playbook \
--syntax-check plays/cache.yaml
- cmd: |-
ansible-playbook \
--ask-become-pass plays/cache.yaml \
--limit {{ .limit }} \
--forks 3
netdata:
desc: Deploy the Netdata configurations for parents and children
silent: true
cmds:
- cmd: |-
ansible-playbook \
--syntax-check plays/netdata.yaml
- cmd: |-
ansible-playbook \
--ask-become-pass plays/netdata.yaml \
--limit {{ .limit }} \
--forks 5
clean:
desc: Clean up the temporary files from the repository
summary: |
Remove any generated configuration files and temporary files from the repository.
run: once
silent: true
cmds:
- cmd: rm -rf .cache
- cmd: rm -rf .task