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