aboutsummaryrefslogtreecommitdiff
path: root/roles/proxmox/debian_cloudinit/tasks
diff options
context:
space:
mode:
Diffstat (limited to 'roles/proxmox/debian_cloudinit/tasks')
-rw-r--r--roles/proxmox/debian_cloudinit/tasks/main.yml115
1 files changed, 115 insertions, 0 deletions
diff --git a/roles/proxmox/debian_cloudinit/tasks/main.yml b/roles/proxmox/debian_cloudinit/tasks/main.yml
new file mode 100644
index 0000000..8ed7dfd
--- /dev/null
+++ b/roles/proxmox/debian_cloudinit/tasks/main.yml
@@ -0,0 +1,115 @@
1- name: check if id already exists
2 stat:
3 path: "/etc/pve/qemu-server/{{ ci_base_id }}.conf"
4 register: stat_result
5
6- meta: end_play
7 when: stat_result.stat.exists
8
9- name: install packages
10 package:
11 name:
12 - python3-pip
13 - python3-requests
14
15- name: ensure latest version of proxmoxer is installed
16 become: yes
17 become_user: "{{ proxmox_username }}"
18 pip:
19 name: proxmoxer==2.0.0
20
21- name: download the hashes
22 get_url:
23 url: "https://cloud.debian.org/images/cloud/bookworm/latest/SHA512SUMS"
24 dest: "{{ ci_target_dir }}"
25
26- name: get the hash
27 changed_when: false
28 args:
29 executable: /bin/bash
30 shell: |
31 set -eo pipefail
32 grep debian-12-genericcloud-amd64.qcow2 {{ ci_target_dir }}/SHA512SUMS | cut -d ' ' -f 1
33 register: sha512sum
34
35- name: download the cloud image
36 get_url:
37 url: "https://cloud.debian.org/images/cloud/bookworm/latest/debian-12-genericcloud-amd64.qcow2"
38 dest: "{{ ci_target_dir }}"
39 checksum: "sha512:{{ sha512sum.stdout }}"
40
41- name: remove any existing api token
42 command: "pveum user token remove vmadmin@pam ansible"
43 register: result
44 changed_when: result.rc == 0
45 failed_when: result.rc not in [0,255]
46
47- name: create api token
48 register: api_token
49 changed_when: result.rc == 0
50 args:
51 executable: /bin/bash
52 shell: |
53 set -eo pipefail
54 pveum user token add vmadmin@pam ansible --privsep 0 --output-format yaml | grep value | cut -d ' ' -f 2
55
56- name: create vm
57 become: yes
58 become_user: "{{ proxmox_username }}"
59 community.general.proxmox_kvm:
60 api_host: proxmox.home.local
61 api_user: "{{ proxmox_api_user }}"
62 api_token_id: "ansible"
63 api_token_secret: "{{ api_token.stdout }}"
64 node: proxmox
65 # basic settings
66 vmid: "{{ ci_base_id }}"
67 memory: "{{ ci_memory_size }}"
68 sockets: "{{ cpu_sockets }}"
69 cores: "{{ cpu_cores }}"
70 bios: "{{ bios_type }}"
71 agent: "{{ vm_agent }}"
72 state: "present"
73 # display settings
74 serial:
75 "serial0": "socket"
76 vga: "serial0"
77 # disks and boot settings
78 scsihw: "virtio-scsi-pci"
79 ide:
80 ide2: "{{ ci_storage }}:cloudinit"
81 boot: "c"
82 bootdisk: "scsi0"
83 onboot: "{{ vm_onboot }}"
84 # cloud-init
85 citype: "nocloud"
86 ciuser: "{{ ci_user }}"
87 cipassword: "{{ ci_password }}"
88 sshkeys: "{{ ci_sshkey }}"
89 # network
90 net:
91 net0: "virtio,bridge={{ ci_bridge }},tag={{ ci_vlan }}"
92 nameservers: "{{ nameserver }}"
93 template: "yes"
94
95- name: import the cloud image
96 changed_when: false
97 command:
98 cmd: "qm importdisk {{ ci_base_id }} {{ ci_target_dir }}/debian-12-genericcloud-amd64.qcow2 {{ ci_storage }}"
99 creates: "/dev/pve/vm-{{ ci_base_id }}-disk-0"
100
101- name: attach the cloud image as a new disk
102 changed_when: false
103 command:
104 cmd: "qm set {{ ci_base_id }} --scsi0 {{ ci_storage }}:vm-{{ ci_base_id }}-disk-0"
105
106- name: resize disk to standard size
107 changed_when: false
108 command:
109 cmd: "qm resize {{ ci_base_id }} scsi0 {{ ci_disk_size }}"
110
111- name: remove api token
112 command: "pveum user token remove vmadmin@pam ansible"
113 register: result
114 changed_when: result.rc == 0
115 failed_when: result.rc not in [0,255]