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/cloudinit_guest/defaults/main.yml | 7 +++ roles/proxmox/cloudinit_guest/tasks/main.yml | 80 +++++++++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 roles/proxmox/cloudinit_guest/defaults/main.yml create mode 100644 roles/proxmox/cloudinit_guest/tasks/main.yml (limited to 'roles/proxmox/cloudinit_guest') diff --git a/roles/proxmox/cloudinit_guest/defaults/main.yml b/roles/proxmox/cloudinit_guest/defaults/main.yml new file mode 100644 index 0000000..a562ff3 --- /dev/null +++ b/roles/proxmox/cloudinit_guest/defaults/main.yml @@ -0,0 +1,7 @@ +vm_onboot: yes +vm_agent: yes +vm_bridge: vmbr0 +vm_full_clone: yes +memory_size: 512 +cpu_cores: 1 +cpu_sockets: 1 diff --git a/roles/proxmox/cloudinit_guest/tasks/main.yml b/roles/proxmox/cloudinit_guest/tasks/main.yml new file mode 100644 index 0000000..ab958dc --- /dev/null +++ b/roles/proxmox/cloudinit_guest/tasks/main.yml @@ -0,0 +1,80 @@ +- name: check if id already exists + stat: + path: "/etc/pve/qemu-server/{{ ci_base_id }}.conf" + register: stat_result + +- meta: end_play + when: stat_result.stat.exists + +- name: install packages + package: + name: + - python3-pip + - python3-requests + +- name: ensure latest version of proxmoxer is installed + become: yes + become_user: "{{ proxmox_username }}" + pip: + name: proxmoxer==2.0.0 + +- 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: clone template and create guest + 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 + full: "{{ vm_full_clone }}" + clone: arbitrary + vmid: "{{ template_id }}" + newid: "{{ vm_id }}" + name: "{{ vm_name }}" + memory: "{{ memory_size }}" + sockets: "{{ cpu_sockets }}" + cores: "{{ cpu_cores }}" + bios: "{{ bios_type }}" + ipconfig: + ipconfig0: "ip={{ ip_addr }},gw={{ gateway }}" + net: + net0: "virtio,bridge={{ vm_bridge }},tag={{ vm_vlan }}" + nameservers: "{{ nameserver }}" + onboot: "{{ vm_onboot }}" + agent: "{{ vm_agent }}" + state: present + +- name: start vmn + 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 + vmid: "{{ vm_id }}" + state: started + +- 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