From c0ca32da2600e5896d0294212f51c4437741f341 Mon Sep 17 00:00:00 2001 From: guppy Date: Wed, 19 Apr 2023 17:44:52 +0200 Subject: [PATCH] :wqAjout create-vm-template --- ansible/create-vm-template.yaml | 46 +++++++++++++++++++++++++++++++++ ansible/inventory.ini | 2 ++ 2 files changed, 48 insertions(+) create mode 100644 ansible/create-vm-template.yaml create mode 100644 ansible/inventory.ini diff --git a/ansible/create-vm-template.yaml b/ansible/create-vm-template.yaml new file mode 100644 index 0000000..70eccb6 --- /dev/null +++ b/ansible/create-vm-template.yaml @@ -0,0 +1,46 @@ +--- +- name: "create VM template" + hosts: pve + gather_facts: no + vars: + vm: + cloud_image_url: https://cloud.debian.org/images/cloud/bullseye/latest/debian-11-genericcloud-amd64.qcow2 + cloud_image_path: /tmp/debian-11-cloudinit-amd64.qcow2 + template_id: 1001 + template_name: debian-11-cloudinit-template + template_memory: 4096 + template_bridge: vmbr0 + 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 {{ vm.template_id }} --name {{ vm.template_name }} --memory {{ vm.template_memory }} --net0 virtio,bridge={{ vm.template_bridge }}" + become: yes + + - name: import disk image + command: "qm importdisk {{ vm.template_id }} {{ vm.cloud_image_path }} local-lvm" + become: yes + + - name: configure VM to use imported image + command: "qm set {{ vm.template_id }} --scsihw virtio-scsi-pci --scsi0 local-lvm:vm-{{ vm.template_id }}-disk-0" + become: yes + + - name: add cloud-init image as CDROM + command: "qm set {{ vm.template_id }} --ide2 local-lvm:cloudinit" + become: yes + + - name: configure boot from the image + command: "qm set {{ vm.template_id }} --boot c --bootdisk scsi0" + become: yes + + - name: attach serial console + command: "qm set {{ vm.template_id }} --serial0 socket --vga serial0" + become: yes + + - name: create template + command: "qm template {{ vm.template_id }}" + become: yes diff --git a/ansible/inventory.ini b/ansible/inventory.ini new file mode 100644 index 0000000..2922591 --- /dev/null +++ b/ansible/inventory.ini @@ -0,0 +1,2 @@ +[pve] +X.X.X.X