forked from geerlingguy/pi-cluster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.yml
145 lines (118 loc) · 3.49 KB
/
main.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
---
- name: Set up cluster-wide configuration.
hosts: cluster
gather_facts: true
become: true
handlers:
- name: reboot-pi
ansible.builtin.reboot:
vars_files:
- config.yml
tasks:
- name: Ensure cgroups are configured correctly in cmdline.txt.
ansible.builtin.replace:
path: /boot/firmware/cmdline.txt
regexp: '^([\w](?!.*\b{{ item }}\b).*)$'
replace: '\1 {{ item }}'
with_items:
- "cgroup_memory=1"
- "cgroup_enable=memory"
notify: reboot-pi
when: ansible_distribution == 'Debian'
- name: Ensure cgroups are configured correctly in ubuntuEnv.txt.
ansible.builtin.replace:
path: /boot/firmware/ubuntuEnv.txt
regexp: '^(bootargs=[\w](?!.*\b{{ item }}\b).*)$'
replace: '\1 {{ item }}'
with_items:
- "cgroup_memory=1"
- "cgroup_enable=memory"
notify: reboot-pi
when: ansible_distribution == 'Ubuntu'
- name: Download K3s install script.
ansible.builtin.get_url:
url: https://get.k3s.io
dest: "~/k3s_install.sh"
mode: a+x
- name: Install required dependencies
ansible.builtin.apt:
name: nfs-common
state: present
- name: Configure storage node.
hosts: storage
gather_facts: false
become: true
handlers:
- name: restart nfs
ansible.builtin.service:
name: nfs-server
state: restarted
vars_files:
- config.yml
tasks:
- name: Set up storage.
include_tasks: tasks/storage/{{ storage_type }}.yml
- name: Configure the control plane.
hosts: control_plane
gather_facts: false
become: true
vars_files:
- config.yml
tasks:
- name: Install K3s on control plane (takes a while).
ansible.builtin.shell: >-
~/k3s_install.sh >> ~/k3s_install_log.txt
args:
chdir: "~"
creates: /var/lib/rancher/k3s/server/node-token
- name: Get node token.
ansible.builtin.command: cat /var/lib/rancher/k3s/server/node-token
changed_when: false
register: node_token_output
- name: Set node_token fact.
ansible.builtin.set_fact:
node_token: "{{ node_token_output.stdout_lines[0] }}"
- name: Ensure required dependencies are installed.
ansible.builtin.package:
name:
- python3-pip
- python3-setuptools
- python3-openshift
- python3-yaml
- build-essential
- golang
- git
state: present
become: true
- name: Ignore PEP 668 because it's silly.
ansible.builtin.file:
path: /usr/lib/python3.11/EXTERNALLY-MANAGED
state: absent
become: true
- name: Configure the worker nodes.
hosts: nodes
gather_facts: false
become: true
vars_files:
- config.yml
tasks:
- name: Install K3s on nodes (takes a while).
ansible.builtin.shell: >-
K3S_URL="https://{{ groups['control_plane'][0] }}:6443"
K3S_TOKEN="{{ hostvars[groups['control_plane'][0]]['node_token'] }}"
~/k3s_install.sh >> ~/k3s_install_log.txt
args:
chdir: "~"
creates: /var/lib/rancher/k3s/agent/kubelet.kubeconfig
- name: Set up Helm.
import_playbook: tasks/kubernetes/helm.yml
tags: ['helm']
- name: Set up NFS PVCs.
import_playbook: tasks/kubernetes/nfs.yml
tags: ['nfs']
- name: Set up Prometheus.
import_playbook: tasks/kubernetes/prometheus.yml
tags: ['prometheus']
- name: Set up Drupal.
import_playbook: tasks/kubernetes/drupal.yml
tags: ['drupal']