-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathprovision_vms.yml
112 lines (111 loc) · 4.05 KB
/
provision_vms.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
---
- name: Deploy VMs
hosts: localhost
tasks:
- name: Create the 'linuxvm' namespace
kubernetes.core.k8s:
name: linuxvm
kind: Namespace
api_version: v1
state: present
- name: Create VM
kubernetes.core.k8s:
definition:
apiVersion: kubevirt.io/v1
kind: VirtualMachine
metadata:
name: "{{ item.role }}-{{ item.env }}-{{ '%02d' | format(item.id) }}"
namespace: linuxvm
labels:
app: "{{ item.role }}-{{ item.env }}-{{ '%02d' | format(item.id) }}"
kubevirt.io/dynamic-credentials-support: 'true'
vm.kubevirt.io/template: rhel9-server-small
vm.kubevirt.io/template.namespace: openshift
vm.kubevirt.io/template.revision: '1'
vm.kubevirt.io/template.version: v0.26.0
spec:
running: true
dataVolumeTemplates:
- apiVersion: cdi.kubevirt.io/v1beta1
kind: DataVolume
metadata:
name: "{{ item.role }}-{{ item.env }}-{{ '%02d' | format(item.id) }}"
spec:
sourceRef:
kind: DataSource
name: rhel9
namespace: openshift-virtualization-os-images
storage:
resources:
requests:
storage: 30Gi
template:
metadata:
labels:
kubevirt.io/domain: "{{ item.role }}-{{ item.env }}-{{ '%02d' | format(item.id) }}"
kubevirt.io/size: small
spec:
architecture: amd64
domain:
cpu:
cores: 1
sockets: 1
threads: 1
devices:
disks:
- disk:
bus: virtio
name: rootdisk
- disk:
bus: virtio
name: cloudinitdisk
interfaces:
- macAddress: "02:f3:be:00:00:{{ '%02x' | format(item.id) }}"
masquerade: {}
model: virtio
name: default
networkInterfaceMultiqueue: true
rng: {}
features:
acpi: {}
smm:
enabled: true
firmware:
bootloader:
efi: {}
machine:
type: pc-q35-rhel9.2.0
memory:
guest: 2Gi
networks:
- name: default
pod: {}
terminationGracePeriodSeconds: 180
volumes:
- dataVolume:
name: "{{ item.role }}-{{ item.env }}-{{ '%02d' | format(item.id) }}"
name: rootdisk
- cloudInitConfigDrive:
userData: |
#cloud-config
users:
- name: cloud-user
sudo: ['ALL=(ALL) NOPASSWD: ALL']
groups: wheel
shell: /bin/bash
ssh_authorized_keys:
- "{{ ssh_public_key }}"
passwd: "{{ vm_password }}"
lock_passwd: false
chpasswd:
list: |
cloud-user:{{ vm_password }}
expire: False
name: cloudinitdisk
loop:
- { role: "web", env: "prod", id: 1 }
- { role: "app", env: "prod", id: 2 }
- { role: "db", env: "prod", id: 3 }
- { role: "web", env: "dev", id: 4 }
- { role: "app", env: "dev", id: 5 }
- { role: "db", env: "dev", id: 6 }