-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexercise9-fix.yaml
101 lines (90 loc) · 2.77 KB
/
exercise9-fix.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
- name: Fixing the exercise9
hosts: localhost
gather_facts: true
vars:
user: "{{ lookup('env', 'USER') }}"
tasks:
- name: Clean the exercise9 vm
kubernetes.core.k8s:
state: absent
template: "exercise9-vm.yaml.j2"
register: cleanvm
until: cleanvm is succeeded
retries: 60
delay: 10
failed_when: cleanvm is failed or cleanvm.failed
- name: Wait for the Virtual Machine to be removed
kubernetes.core.k8s_info:
kind: VirtualMachine
namespace: "namespace-{{ user }}"
name: "exercise9"
register: cleanvm
retries: 60
delay: 2
until: cleanvm.resources | length == 0
# - name: Removing the idrsa-exercise9 secret
# kubernetes.core.k8s:
# state: absent
# kind: Secret
# name: idrsa-exercise9
# namespace: "namespace-{{ user }}"
# register: idrsa
# until: idrsa is succeeded
# retries: 60
# delay: 10
# failed_when: idrsa is failed or idrsa.failed
- name: Create SSH config file with StrictHostKeyChecking no
ansible.builtin.copy:
dest: '/home/{{ user }}/.ssh/config'
content: |
Host *
StrictHostKeyChecking no
UserKnownHostsFile /dev/null
owner: '{{ user }}'
group: '{{ user }}'
mode: '0600'
- name: Read the content of the file
ansible.builtin.slurp:
src: '/home/{{ user }}/.ssh/id_rsa.pub'
register: idrsapub
- name: Store base64 encoded content in a variable
ansible.builtin.set_fact:
encodedsshpubkey: "{{ idrsapub.content }}"
- name: Create the idrsa secret
kubernetes.core.k8s:
state: present
template: "exercise9-secret.yaml.j2"
register: secretidrsa
until: secretidrsa is succeeded
retries: 60
delay: 10
failed_when: secretidrsa is failed or secretidrsa.failed
- name: Creating the exercise9 virtual machine
kubernetes.core.k8s:
state: present
template: "exercise9-vm.yaml.j2"
register: breakvm
until: breakvm is succeeded
retries: 60
delay: 10
failed_when: breakvm is failed or breakvm.failed
- name: Wait for exercise9
ansible.builtin.command:
cmd: virtctl ssh -i /home/{{ user }}/.ssh/id_rsa lab-user@exercise9
ignore_errors: true
no_log: false
register: testssh
until:
- testssh.rc == 0
retries: 20
delay: 30
- name: Patch the Virtual Machine exercise9 runStrategy to Manual
kubernetes.core.k8s:
api_version: kubevirt.io/v1
kind: VirtualMachine
name: exercise9
namespace: "namespace-{{ user }}"
definition:
spec:
runStrategy: Manual
state: patched