-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdeploy-cluster.yml
184 lines (149 loc) · 5.03 KB
/
deploy-cluster.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
- hosts: localhost
become: no
gather_facts: no
tasks:
- name: Delete VM ssh fingerprint
become: false
shell: "ssh-keygen -f ~/.ssh/known_hosts -R {{ hostvars[item]['ansible_host'] }}"
register: known_hosts_delete
changed_when: "'updated' in known_hosts_delete.stdout"
loop: "{{ groups['k8s_cluster'] }}"
- name: Accept server SSH host keys
become: false
shell: |
ssh-keyscan -H {{ hostvars[item]['ansible_host'] }} >> ~/.ssh/known_hosts
register: known_hosts_script
until: known_hosts_script.rc == 0
retries: 5
delay: 1
changed_when: known_hosts_script.rc != 0
loop: "{{ groups['k8s_cluster'] }}"
- name: Create dir for kubeconfig
file:
path: ~/.kube
state: directory
- hosts: k8s_cluster
become: yes
gather_facts: yes
vars:
become_pass: '{{ ansible_executor_become_pass }}'
pre_tasks:
- name: Disable cloud-init
ansible.builtin.lineinfile:
path: /etc/cloud/cloud-init.disabled
line: cloud-init=disabled
create: yes
state: present
- name: Print ip address of VW
ansible.builtin.debug:
var: hostvars[item]['ansible_eth1']['ipv4']['address']
loop: "{{ groups['all'] }}"
- name: Run the equivalent of "apt-get update" as a separate step
ansible.builtin.apt:
update_cache: yes
- name: Find timezone
ansible.builtin.command: timedatectl
register: timedate_output
changed_when: false
- name: Set time zone
ansible.builtin.command: timedatectl set-timezone Europe/Moscow
when: '"Moscow" not in timedate_output.stdout'
- name: Fill /etc/hosts with hosts entry
ansible.builtin.lineinfile:
path: /etc/hosts
line: "{{ hostvars[item]['ansible_host'] }} {{ item }}"
loop: "{{ groups['k8s_cluster'] }}"
- name: Add VIP entry in /etc/hosts
ansible.builtin.lineinfile:
path: /etc/hosts
line: "{{ k8s_cp }} k8s-cp"
- name: Set Google DNS as primary in OS
ansible.builtin.lineinfile:
path: /etc/resolv.conf
regexp: '^nameserver'
line: nameserver 8.8.8.8
- name: Install nessesary package
block:
- name: Install pip
ansible.builtin.package:
name: python3-pip
state: present
- name: Install jq
ansible.builtin.package:
name: jq
state: present
- name: Install kubernetes SDK
ansible.builtin.pip:
name: "{{ item }}"
loop:
- kubernetes
- PyYAML
- jsonpatch
- kubernetes-validate
when: kubernetes_role == 'first-control-node'
tasks:
- name: Configure ntp server (if cluster has more than one node)
ansible.builtin.import_role:
name: ansible-ntp-master
when: groups['k8s_cluster'] | length > 1
- name: Set up Haproxy on control node and gateways (if set)
ansible.builtin.import_role:
name: geerlingguy.haproxy
when: haproxy_server
- name: Install containerd
ansible.builtin.import_role:
name: geerlingguy.containerd
- name: Create kubernetes cluster
ansible.builtin.import_role:
name: role-kubernetes
- name: Install Helm on first control node
ansible.builtin.import_role:
name: role-helm
when: kubernetes_role == 'first-control-node'
# Deploy infastructure component with helm
- hosts: k8s_cluster
become: false
gather_facts: false
vars_files:
- ansible_vault_secret.yml
tasks:
- name: Deploy infrastucture and application
when: kubernetes_role == 'first-control-node'
block:
- name: Get ansible host executer username
become: false
ansible.builtin.command: whoami
register: ansible_host_username
changed_when: false
- name: Setup Cilium if set
ansible.builtin.import_role:
name: role-cilium
when: cni_type == "cilium"
- name: Setup kube-prometheus-stack
ansible.builtin.import_role:
name: role-prometheus-stack
- name: Setup Metallb if set
ansible.builtin.import_role:
name: role-metallb
when: enable_metallb
- name: Setup Nginx ingress
ansible.builtin.import_role:
name: role-ingress
- name: Setup local-path-provisioner
ansible.builtin.import_role:
name: role-local-path-provisioner
- name: Setup loki-stack
ansible.builtin.import_role:
name: role-loki-stack
- name: Setup minio
ansible.builtin.import_role:
name: role-minio
- name: Setup elasticsearch and kibana
ansible.builtin.import_role:
name: roles-es-kibana
- name: Setup libretranslate
ansible.builtin.import_role:
name: role-libretranslate
- name: Setup application
ansible.builtin.import_role:
name: role-application