From 95b73daa36b23565a8566f71f9b202d3459b685f Mon Sep 17 00:00:00 2001 From: Sam Chudnick Date: Sun, 25 Jun 2023 09:52:36 -0400 Subject: Initial Commit --- roles/proxmox/fedora_cloudinit/defaults/main.yml | 8 ++ roles/proxmox/fedora_cloudinit/tasks/main.yml | 122 +++++++++++++++++++++++ 2 files changed, 130 insertions(+) create mode 100644 roles/proxmox/fedora_cloudinit/defaults/main.yml create mode 100644 roles/proxmox/fedora_cloudinit/tasks/main.yml (limited to 'roles/proxmox/fedora_cloudinit') diff --git a/roles/proxmox/fedora_cloudinit/defaults/main.yml b/roles/proxmox/fedora_cloudinit/defaults/main.yml new file mode 100644 index 0000000..fb44657 --- /dev/null +++ b/roles/proxmox/fedora_cloudinit/defaults/main.yml @@ -0,0 +1,8 @@ +ci_target_dir: "/home/{{ci_user}}" +ci_memory_size: 512 +ci_base_id: 1001 +ci_storage: "local-lvm" +ci_disk_size: "10G" +ci_user: "initadmin" +ssh_key_local: files/id_rsa.pub +ssh_key_dest: /tmp/ci_sshkey 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 @@ +- name: download the hashes + get_url: + url: "https://getfedora.org/static/checksums/36/images/Fedora-Cloud-36-1.5-x86_64-CHECKSUM" + dest: "{{ ci_target_dir }}" + +- name: install gpg + package: + name: gnupg + state: latest + +- name: download the GPG key + get_url: + url: "https://getfedora.org/static/fedora.gpg" + dest: "{{ ci_target_dir }}" + +- name: import gpg key + changed_when: false + args: + executable: /bin/bash + shell: | + set -eo pipefail + cat {{ ci_target_dir }}/fedora.gpg | gpg --import + +- name: verify checksum file + command: + cmd: "gpg --verify {{ ci_target_dir }}/Fedora-Cloud-36-1.5-x86_64-CHECKSUM" + register: result + changed_when: false + failed_when: result.rc > 0 + +- name: fail if unable to gpg verify checksums + fail: + msg: "failed to verify the checksums" + when: result.rc > 0 + +- name: get the hash + shell: + cmd: "grep 'qcow2)' {{ ci_target_dir }}/Fedora-Cloud-36-1.5-x86_64-CHECKSUM | cut -d '=' -f 2 | tr -d ' '" + changed_when: false + register: sha256sum + +- name: download the cloud image + get_url: + url: "https://download.fedoraproject.org/pub/fedora/linux/releases/36/Cloud/x86_64/images/Fedora-Cloud-Base-36-1.5.x86_64.qcow2" + dest: "{{ ci_target_dir }}" + checksum: "sha256:{{ sha256sum.stdout }}" + +- name: remove any existing api token + command: "pveum user token remove vmadmin@pam ansible" + register: result + changed_when: result.rc == 0 + failed_when: result.rc not in [0,255] + +- name: create api token + register: api_token + changed_when: result.rc == 0 + args: + executable: /bin/bash + shell: | + set -eo pipefail + pveum user token add vmadmin@pam ansible --privsep 0 --output-format yaml | grep value | cut -d ' ' -f 2 + +- name: create vm + become: yes + become_user: "{{ proxmox_username }}" + community.general.proxmox_kvm: + api_host: proxmox.home.local + api_user: "{{ proxmox_api_user }}" + api_token_id: "ansible" + api_token_secret: "{{ api_token.stdout }}" + node: proxmox + # basic settings + vmid: "{{ ci_base_id }}" + memory: "{{ ci_memory_size }}" + sockets: "{{ cpu_sockets }}" + cores: "{{ cpu_cores }}" + bios: "{{ bios_type }}" + agent: "{{ vm_agent }}" + state: "present" + # display settings + serial: + "serial0": "socket" + vga: "serial0" + # disks and boot settings + scsihw: "virtio-scsi-pci" + ide: + ide2: "{{ ci_storage }}:cloudinit" + boot: "c" + bootdisk: "scsi0" + onboot: "{{ vm_onboot }}" + # cloud-init + citype: "nocloud" + ciuser: "{{ ci_user }}" + cipassword: "{{ ci_password }}" + sshkeys: "{{ ci_sshkey }}" + # network + net: + net0: "virtio,bridge={{ ci_bridge }},tag={{ ci_vlan }}" + nameservers: "{{ nameserver }}" + template: "yes" + +- name: import the cloud image + changed_when: false + command: + cmd: "qm importdisk {{ ci_base_id }} {{ ci_target_dir }}/Fedora-Cloud-Base-36-1.5.x86_64.qcow2 {{ ci_storage }}" + creates: "/dev/pve/vm-{{ ci_base_id }}-disk-0" + +- name: attach the cloud image as a new disk + changed_when: false + command: + cmd: "qm set {{ ci_base_id }} --scsi0 {{ ci_storage }}:vm-{{ ci_base_id }}-disk-0" + +- name: resize disk to standard size + changed_when: false + command: + cmd: "qm resize {{ ci_base_id }} scsi0 {{ ci_disk_size }}" + +- name: remove api token + command: "pveum user token remove vmadmin@pam ansible" + register: result + changed_when: result.rc == 0 + failed_when: result.rc not in [0,255] -- cgit v1.2.3