forked from datastrophic/kubernetes-deployment
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate-vm-template.yaml
44 lines (37 loc) · 1.48 KB
/
create-vm-template.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
---
- hosts: pve
gather_facts: no
name: "create VM template"
vars:
vm:
cloud_image_url: https://cloud-images.ubuntu.com/releases/22.04/release/ubuntu-22.04-server-cloudimg-amd64.img
cloud_image_path: /tmp/ubuntu-22.04-server-cloudimg-amd64.qcow2
template_name: ubuntu-22.04-server-cloudimg-amd64-310822-template
template_memory: 4096
tasks:
- name : download cloud image
get_url:
url: "{{ vm.cloud_image_url }}"
dest: "{{ vm.cloud_image_path }}"
mode: 0700
- name: create a VM to use as a template
command: "qm create {{ template_id }} --name {{ vm.template_name }} --memory {{ vm.template_memory }} --net0 virtio,bridge=vmbr0"
become: yes
- name: import disk image
command: "qm importdisk {{ template_id }} {{ vm.cloud_image_path }} local-lvm"
become: yes
- name: configure VM to use imported image
command: "qm set {{ template_id }} --scsihw virtio-scsi-pci --scsi0 local-lvm:vm-{{ template_id }}-disk-0"
become: yes
- name: add cloud-init image as CDROM
command: "qm set {{ template_id }} --ide2 local-lvm:cloudinit"
become: yes
- name: configure boot from the image
command: "qm set {{ template_id }} --boot c --bootdisk scsi0"
become: yes
- name: attach serial console
command: "qm set {{ template_id }} --serial0 socket --vga serial0"
become: yes
- name: create template
command: "qm template {{ template_id }}"
become: yes