forked from kubealex/libvirt-k8s-provisioner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path07_provisioning_nfs.yml
233 lines (206 loc) · 6.33 KB
/
07_provisioning_nfs.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
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
- name: This play provisions NFS Server VM for the cluster
hosts: vm_host
become: true
vars_files:
- vars/k8s_cluster.yml
tasks:
- name: Provision NFS Server VM
block:
- terraform:
project_path: "files/terraform/nfs"
force_init: true
variables:
hostname: "{{ k8s.cluster_name }}-nfs"
domain: "{{ k8s.network.domain }}"
nfs_fsSize: "{{ k8s.storage.nfs_fsSize }}"
os: "{{ 'ubuntu' if k8s.cluster_os == 'Ubuntu' else 'centos' }}"
libvirt_network: "{{ k8s.cluster_name }}"
libvirt_pool: "{{ k8s.cluster_name }}"
os_image_name: "{{ image_name }}.qcow2"
state: present
register: output_nfs
- name: Add NFS server to inventory
add_host:
hostname: '{{ k8s.cluster_name }}-nfs.{{ k8s.network.domain }}'
node_hostname: '{{ k8s.cluster_name }}-nfs.{{ k8s.network.domain }}'
node_mac: "{{ output_nfs.outputs.macs.value[0]|lower }}"
node_fqdn: "{{ k8s.cluster_name }}-nfs.{{ k8s.network.domain }}"
ansible_ssh_private_key_file: "id_rsa"
ansible_user: kube
ansible_ssh_common_args: '-o StrictHostKeyChecking=no'
groups:
- "nfs"
- name: Ensure to clean known_hosts
known_hosts:
host: "{{ item }}"
path: ~/.ssh/known_hosts
state: absent
loop: "{{ groups['nfs'] }}"
when: k8s.storage.nfs_enabled
- name: Check connection to NFS server
hosts: nfs
gather_facts: no
vars_files:
- vars/k8s_cluster.yml
tasks:
- block:
- name: Wait 600 seconds for target connection to become reachable/usable
wait_for_connection:
timeout: 600
delay: 0
- ping:
when: k8s.storage.nfs_enabled
- name: Setup NFS server
hosts: nfs
become: true
vars_files:
- vars/k8s_cluster.yml
tasks:
- name: Handle setup of NFS server
block:
- name: Set ethernet adapter facts
set_fact:
interface: eth0
when: k8s.cluster_os == 'CentOS'
- name: Set ethernet adapter facts
set_fact:
interface: ens3
when: k8s.cluster_os == 'Ubuntu'
- name: Manage packages on CentOS
block:
- name: Upgrade all packages
yum:
name: '*'
state: latest
- name: Install packages
yum:
name: "{{ packages_server.centos }}"
state: latest
when: k8s.cluster_os == 'CentOS'
- name: Manage packages on Ubuntu
block:
- name: Upgrade all packages
apt:
name: '*'
state: latest
- name: Install packages
apt:
name: "{{ packages_server.ubuntu }}"
state: latest
when: k8s.cluster_os == 'Ubuntu'
- name: Ensure NFS Service is enabled
service:
name: "{{ item }}"
enabled: true
state: started
loop:
- nfs-server
when: k8s.cluster_os == 'CentOS'
- name: Ensure NFS Service is enabled
service:
name: "{{ item }}"
enabled: true
state: started
loop:
- nfs-kernel-server
when: k8s.cluster_os == 'Ubuntu'
- name: Ensure firewalld Service is enabled
service:
name: firewalld
enabled: true
state: started
- name: Set interface to internal zone
shell: nmcli connection modify System\ eth0 connection.zone internal
when: k8s.cluster_os == 'CentOS'
- name: Stop NetworkManager
service:
name: NetworkManager
state: stopped
- name: Adding interface to firewall internal zone
ansible.posix.firewalld:
zone: internal
interface: "{{ interface }}"
permanent: yes
state: enabled
- name: Start NetworkManager
service:
name: NetworkManager
state: started
enabled: true
- name: Allow service for internal zone
ansible.posix.firewalld:
zone: internal
state: enabled
permanent: yes
service: "{{ item }}"
loop: "{{ services }}"
- name: Allow ports for internal zone
ansible.posix.firewalld:
zone: internal
state: enabled
permanent: yes
port: "{{ item }}"
loop: "{{ ports }}"
- name: Reload firewalld service
service:
name: firewalld
state: restarted
- name: Ensure partition is present for NFS
parted:
device: /dev/vdb
label: msdos
number: 1
part_start: 0%
part_end: 100%
state: present
- name: Create filesystem on partitions
filesystem:
fstype: ext4
dev: /dev/vdb1
- name: Create mountpoints
file:
path: "{{ k8s.storage.nfs_export }}"
state: directory
owner: nobody
group: nobody
mode: 0777
recurse: yes
when: k8s.cluster_os == 'CentOS'
- name: Create mountpoints
file:
path: "{{ k8s.storage.nfs_export }}"
state: directory
owner: nobody
group: nogroup
mode: 0777
recurse: yes
when: k8s.cluster_os == 'Ubuntu'
- name: Mount the filesystems
mount:
fstype: ext4
src: /dev/vdb1
path: "{{ k8s.storage.nfs_export }}"
state: mounted
- name: Create mountpoints
file:
path: /etc/exports.d
state: directory
- name: Populate exports with created path
copy:
content: "{{ k8s.storage.nfs_export }} *(rw,sync,no_subtree_check,no_root_squash,no_all_squash,insecure)"
dest: /etc/exports.d/nfs.exports
- name: Reload NFS Service
service:
name: "{{ item }}"
state: restarted
loop:
- nfs-server
when: k8s.cluster_os == 'CentOS'
- name: Reload NFS Service
service:
name: "{{ item }}"
state: restarted
loop:
- nfs-kernel-server
when: k8s.cluster_os == 'Ubuntu'
when: k8s.storage.nfs_enabled