|
14 | 14 | - epel_repositories |
15 | 15 | tasks: |
16 | 16 | - name: disable swap |
17 | | - command: swapoff -a |
| 17 | + ansible.builtin.command: swapoff -a |
18 | 18 |
|
19 | 19 | - name: deconfigure swap |
20 | | - mount: |
| 20 | + ansible.posix.mount: |
21 | 21 | src: /swapfile |
22 | 22 | fstype: swap |
23 | 23 | path: none |
24 | 24 | state: absent |
25 | 25 |
|
26 | 26 | - name: modprobe br_netfilter |
27 | | - modprobe: |
| 27 | + community.general.modprobe: |
28 | 28 | name: br_netfilter |
29 | 29 |
|
30 | 30 | - name: configure bridge iptables |
31 | | - sysctl: |
| 31 | + ansible.posix.sysctl: |
32 | 32 | name: "{{ item }}" |
33 | 33 | value: 1 |
34 | 34 | sysctl_file: /etc/sysctl.d/k8s.conf |
|
37 | 37 | - net.bridge.bridge-nf-call-iptables |
38 | 38 |
|
39 | 39 | - name: install needed network manager libs |
40 | | - yum: |
| 40 | + ansible.builtin.yum: |
41 | 41 | name: |
42 | 42 | - NetworkManager-glib |
43 | 43 | - NetworkManager |
44 | 44 |
|
45 | 45 | - name: Configure bridge |
46 | | - nmcli: |
| 46 | + community.general.nmcli: |
47 | 47 | state: present |
48 | 48 | type: bridge |
49 | 49 | conn_name: foreman |
50 | 50 |
|
51 | 51 | - name: install docker |
52 | | - yum: |
| 52 | + ansible.builtin.yum: |
53 | 53 | name: docker |
54 | 54 |
|
55 | 55 | - name: enable docker |
56 | | - service: |
| 56 | + ansible.builtin.service: |
57 | 57 | name: docker |
58 | 58 | enabled: true |
59 | 59 | state: started |
60 | 60 |
|
61 | 61 | - name: k8s repo |
62 | | - yum_repository: |
| 62 | + ansible.builtin.yum_repository: |
63 | 63 | name: kubernetes |
64 | 64 | description: Kubernetes |
65 | 65 | baseurl: https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64 |
|
70 | 70 | exclude: kube* |
71 | 71 |
|
72 | 72 | - name: install kubelet kubeadm kubectl |
73 | | - yum: |
| 73 | + ansible.builtin.yum: |
74 | 74 | name: |
75 | 75 | - kubelet-{{ kubernetes_version }} |
76 | 76 | - kubeadm-{{ kubernetes_version }} |
77 | 77 | - kubectl-{{ kubernetes_version }} |
78 | 78 | disable_excludes: kubernetes |
79 | 79 |
|
80 | 80 | - name: create /etc/systemd/system/kubelet.service.d/ |
81 | | - file: |
| 81 | + ansible.builtin.file: |
82 | 82 | path: /etc/systemd/system/kubelet.service.d/ |
83 | 83 | state: directory |
84 | 84 |
|
85 | 85 | - name: enable kubelet accounting |
86 | | - copy: |
| 86 | + ansible.builtin.copy: |
87 | 87 | dest: /etc/systemd/system/kubelet.service.d/11-cgroups.conf |
88 | 88 | content: | |
89 | 89 | [Service] |
90 | 90 | CPUAccounting=true |
91 | 91 | MemoryAccounting=true |
92 | 92 |
|
93 | 93 | - name: reload systemd |
94 | | - systemd: |
| 94 | + ansible.builtin.systemd: |
95 | 95 | daemon_reload: yes |
96 | 96 |
|
97 | 97 | - name: enable kubelet |
98 | | - service: |
| 98 | + ansible.builtin.service: |
99 | 99 | name: kubelet |
100 | 100 | enabled: true |
101 | 101 | state: started |
102 | 102 |
|
103 | 103 | - name: init cluster |
104 | | - command: kubeadm init --pod-network-cidr={{ pod_network }} --apiserver-advertise-address={{ ansible_eth0['ipv4']['address'] }} |
| 104 | + ansible.builtin.command: kubeadm init --pod-network-cidr={{ pod_network }} --apiserver-advertise-address={{ ansible_eth0['ipv4']['address'] }} |
105 | 105 | args: |
106 | 106 | creates: /etc/kubernetes/admin.conf |
107 | 107 |
|
108 | 108 | - name: untaint master |
109 | | - command: kubectl taint nodes --all node-role.kubernetes.io/master- |
| 109 | + ansible.builtin.command: kubectl taint nodes --all node-role.kubernetes.io/master- |
110 | 110 | register: untaint_master |
111 | 111 | failed_when: false |
112 | 112 | changed_when: untaint_master.rc == 0 |
113 | 113 | environment: |
114 | 114 | KUBECONFIG: /etc/kubernetes/admin.conf |
115 | 115 |
|
116 | 116 | - name: deploy flannel |
117 | | - command: kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/{{ flannel_version }}/Documentation/kube-flannel.yml |
| 117 | + ansible.builtin.command: kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/{{ flannel_version }}/Documentation/kube-flannel.yml |
118 | 118 | args: |
119 | 119 | creates: /etc/cni/net.d/10-flannel.conflist |
120 | 120 | environment: |
121 | 121 | KUBECONFIG: /etc/kubernetes/admin.conf |
122 | 122 |
|
123 | 123 | - name: deploy network namespace |
124 | | - command: kubectl apply -f https://github.com/kubevirt/cluster-network-addons-operator/releases/download/{{ network_operator }}/namespace.yaml |
| 124 | + ansible.builtin.command: kubectl apply -f https://github.com/kubevirt/cluster-network-addons-operator/releases/download/{{ network_operator }}/namespace.yaml |
125 | 125 | args: |
126 | 126 | creates: /etc/cni/net.d/multus.d/multus.kubeconfig |
127 | 127 | environment: |
128 | 128 | KUBECONFIG: /etc/kubernetes/admin.conf |
129 | 129 |
|
130 | 130 | - name: deploy network crd |
131 | | - command: kubectl apply -f https://github.com/kubevirt/cluster-network-addons-operator/releases/download/{{ network_operator }}/network-addons-config.crd.yaml |
| 131 | + ansible.builtin.command: kubectl apply -f https://github.com/kubevirt/cluster-network-addons-operator/releases/download/{{ network_operator }}/network-addons-config.crd.yaml |
132 | 132 | args: |
133 | 133 | creates: /etc/cni/net.d/multus.d/multus.kubeconfig |
134 | 134 | environment: |
135 | 135 | KUBECONFIG: /etc/kubernetes/admin.conf |
136 | 136 |
|
137 | 137 | - name: deploy network operator |
138 | | - command: kubectl apply -f https://github.com/kubevirt/cluster-network-addons-operator/releases/download/{{ network_operator }}/operator.yaml |
| 138 | + ansible.builtin.command: kubectl apply -f https://github.com/kubevirt/cluster-network-addons-operator/releases/download/{{ network_operator }}/operator.yaml |
139 | 139 | args: |
140 | 140 | creates: /etc/cni/net.d/multus.d/multus.kubeconfig |
141 | 141 | environment: |
142 | 142 | KUBECONFIG: /etc/kubernetes/admin.conf |
143 | 143 |
|
144 | 144 | - name: deploy kubevirt operator |
145 | | - command: kubectl apply -f https://github.com/kubevirt/kubevirt/releases/download/{{ kubevirt_version }}/kubevirt-operator.yaml |
| 145 | + ansible.builtin.command: kubectl apply -f https://github.com/kubevirt/kubevirt/releases/download/{{ kubevirt_version }}/kubevirt-operator.yaml |
146 | 146 | args: |
147 | 147 | creates: /var/lib/kubelet/device-plugins/kubevirt-tun.sock |
148 | 148 | environment: |
149 | 149 | KUBECONFIG: /etc/kubernetes/admin.conf |
150 | 150 |
|
151 | 151 | - name: deploy kubevirt cr |
152 | | - command: kubectl apply -f https://github.com/kubevirt/kubevirt/releases/download/{{ kubevirt_version }}/kubevirt-cr.yaml |
| 152 | + ansible.builtin.command: kubectl apply -f https://github.com/kubevirt/kubevirt/releases/download/{{ kubevirt_version }}/kubevirt-cr.yaml |
153 | 153 | args: |
154 | 154 | creates: /var/lib/kubelet/device-plugins/kubevirt-tun.sock |
155 | 155 | environment: |
156 | 156 | KUBECONFIG: /etc/kubernetes/admin.conf |
157 | 157 |
|
158 | 158 | - name: check for NetworkAddonsConfig |
159 | | - command: kubectl get networkaddonsconfigs cluster |
| 159 | + ansible.builtin.command: kubectl get networkaddonsconfigs cluster |
160 | 160 | environment: |
161 | 161 | KUBECONFIG: /etc/kubernetes/admin.conf |
162 | 162 | failed_when: false |
163 | 163 | changed_when: false |
164 | 164 | register: netaddonsconfig |
165 | 165 |
|
166 | 166 | - name: prepare NetworkAddonsConfig file |
167 | | - copy: |
| 167 | + ansible.builtin.copy: |
168 | 168 | dest: /tmp/netaddonsconfig |
169 | 169 | content: | |
170 | 170 | apiVersion: networkaddonsoperator.network.kubevirt.io/v1alpha1 |
|
179 | 179 | when: netaddonsconfig.rc != 0 |
180 | 180 |
|
181 | 181 | - name: create NetworkAddonsConfig |
182 | | - command: kubectl create -f /tmp/netaddonsconfig |
| 182 | + ansible.builtin.command: kubectl create -f /tmp/netaddonsconfig |
183 | 183 | environment: |
184 | 184 | KUBECONFIG: /etc/kubernetes/admin.conf |
185 | 185 | when: netaddonsconfig.rc != 0 |
186 | 186 |
|
187 | 187 | - name: install virtctl |
188 | | - get_url: |
| 188 | + ansible.builtin.get_url: |
189 | 189 | url: https://github.com/kubevirt/kubevirt/releases/download/{{ kubevirt_version }}/virtctl-{{ kubevirt_version }}-linux-amd64 |
190 | 190 | dest: /usr/bin/virtctl |
191 | 191 | mode: u=rwx,g=rx,o=rx |
192 | 192 |
|
193 | 193 | - name: wait for the network to be ready |
194 | | - command: kubectl wait networkaddonsconfig cluster --for condition=Ready --timeout=300s |
| 194 | + ansible.builtin.command: kubectl wait networkaddonsconfig cluster --for condition=Ready --timeout=300s |
195 | 195 | environment: |
196 | 196 | KUBECONFIG: /etc/kubernetes/admin.conf |
197 | 197 |
|
198 | 198 | - name: check for bridge-foreman NetworkAttachmentDefinition |
199 | | - command: kubectl get net-attach-def bridge-foreman |
| 199 | + ansible.builtin.command: kubectl get net-attach-def bridge-foreman |
200 | 200 | environment: |
201 | 201 | KUBECONFIG: /etc/kubernetes/admin.conf |
202 | 202 | failed_when: false |
203 | 203 | changed_when: false |
204 | 204 | register: bridge_foreman_net_attach |
205 | 205 |
|
206 | 206 | - name: prepare bridge-foreman NetworkAttachmentDefinition file |
207 | | - copy: |
| 207 | + ansible.builtin.copy: |
208 | 208 | dest: /tmp/bridge-foreman-net-attach-def |
209 | 209 | content: | |
210 | 210 | apiVersion: "k8s.cni.cncf.io/v1" |
|
221 | 221 | when: bridge_foreman_net_attach.rc != 0 |
222 | 222 |
|
223 | 223 | - name: create bridge-foreman NetworkAttachmentDefinition |
224 | | - command: kubectl create -f /tmp/bridge-foreman-net-attach-def |
| 224 | + ansible.builtin.command: kubectl create -f /tmp/bridge-foreman-net-attach-def |
225 | 225 | environment: |
226 | 226 | KUBECONFIG: /etc/kubernetes/admin.conf |
227 | 227 | when: bridge_foreman_net_attach.rc != 0 |
228 | 228 |
|
229 | 229 | - name: check for foreman-account ServiceAccount |
230 | | - command: kubectl get sa foreman-account |
| 230 | + ansible.builtin.command: kubectl get sa foreman-account |
231 | 231 | environment: |
232 | 232 | KUBECONFIG: /etc/kubernetes/admin.conf |
233 | 233 | failed_when: false |
234 | 234 | changed_when: false |
235 | 235 | register: foreman_service_sa |
236 | 236 |
|
237 | 237 | - name: prepare foreman-account ServiceAccount file |
238 | | - copy: |
| 238 | + ansible.builtin.copy: |
239 | 239 | dest: /tmp/foreman-account-sa |
240 | 240 | content: | |
241 | 241 | apiVersion: v1 |
|
259 | 259 | when: foreman_service_sa.rc != 0 |
260 | 260 |
|
261 | 261 | - name: create foreman-account ServiceAccount |
262 | | - command: kubectl create -f /tmp/foreman-account-sa |
| 262 | + ansible.builtin.command: kubectl create -f /tmp/foreman-account-sa |
263 | 263 | environment: |
264 | 264 | KUBECONFIG: /etc/kubernetes/admin.conf |
265 | 265 | when: foreman_service_sa.rc != 0 |
266 | 266 |
|
267 | 267 | - name: create /home/vagrant/.kube |
268 | | - file: |
| 268 | + ansible.builtin.file: |
269 | 269 | path: /home/vagrant/.kube |
270 | 270 | state: directory |
271 | 271 | owner: vagrant |
272 | 272 | group: vagrant |
273 | 273 |
|
274 | 274 | - name: deploy kube config |
275 | | - copy: |
| 275 | + ansible.builtin.copy: |
276 | 276 | src: /etc/kubernetes/admin.conf |
277 | 277 | dest: /home/vagrant/.kube/config |
278 | 278 | remote_src: yes |
279 | 279 | owner: vagrant |
280 | 280 | group: vagrant |
281 | 281 |
|
282 | 282 | - name: get foreman-account secret |
283 | | - shell: "set -o pipefail && kubectl get secrets $(kubectl get sa foreman-account -o jsonpath='{.secrets[0].name}') -o jsonpath='{.data.token}' | base64 -d | xargs" |
| 283 | + ansible.builtin.shell: "set -o pipefail && kubectl get secrets $(kubectl get sa foreman-account -o jsonpath='{.secrets[0].name}') -o jsonpath='{.data.token}' | base64 -d | xargs" |
284 | 284 | environment: |
285 | 285 | KUBECONFIG: /etc/kubernetes/admin.conf |
286 | 286 | changed_when: false |
287 | 287 | register: foreman_account_secret |
288 | 288 |
|
289 | 289 | - name: show foreman-account secret |
290 | | - debug: |
| 290 | + ansible.builtin.debug: |
291 | 291 | msg: "{{ foreman_account_secret.stdout }}" |
0 commit comments