diff options
author | Sam Chudnick <sam@chudnick.com> | 2023-06-25 09:52:36 -0400 |
---|---|---|
committer | Sam Chudnick <sam@chudnick.com> | 2023-06-25 09:52:36 -0400 |
commit | 95b73daa36b23565a8566f71f9b202d3459b685f (patch) | |
tree | cb17b021be70e7868d0ec235a761f0ecdc80f3f2 /roles/proxmox/cloudinit_guest |
Diffstat (limited to 'roles/proxmox/cloudinit_guest')
-rw-r--r-- | roles/proxmox/cloudinit_guest/defaults/main.yml | 7 | ||||
-rw-r--r-- | roles/proxmox/cloudinit_guest/tasks/main.yml | 80 |
2 files changed, 87 insertions, 0 deletions
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 @@ | |||
1 | vm_onboot: yes | ||
2 | vm_agent: yes | ||
3 | vm_bridge: vmbr0 | ||
4 | vm_full_clone: yes | ||
5 | memory_size: 512 | ||
6 | cpu_cores: 1 | ||
7 | 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 @@ | |||
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: remove any existing api token | ||
22 | command: "pveum user token remove vmadmin@pam ansible" | ||
23 | register: result | ||
24 | changed_when: result.rc == 0 | ||
25 | failed_when: result.rc not in [0,255] | ||
26 | |||
27 | - name: create api token | ||
28 | register: api_token | ||
29 | changed_when: result.rc == 0 | ||
30 | args: | ||
31 | executable: /bin/bash | ||
32 | shell: | | ||
33 | set -eo pipefail | ||
34 | pveum user token add vmadmin@pam ansible --privsep 0 --output-format yaml | grep value | cut -d ' ' -f 2 | ||
35 | |||
36 | |||
37 | - name: clone template and create guest | ||
38 | become: yes | ||
39 | become_user: "{{ proxmox_username }}" | ||
40 | community.general.proxmox_kvm: | ||
41 | api_host: proxmox.home.local | ||
42 | api_user: "{{ proxmox_api_user }}" | ||
43 | api_token_id: "ansible" | ||
44 | api_token_secret: "{{ api_token.stdout }}" | ||
45 | node: proxmox | ||
46 | full: "{{ vm_full_clone }}" | ||
47 | clone: arbitrary | ||
48 | vmid: "{{ template_id }}" | ||
49 | newid: "{{ vm_id }}" | ||
50 | name: "{{ vm_name }}" | ||
51 | memory: "{{ memory_size }}" | ||
52 | sockets: "{{ cpu_sockets }}" | ||
53 | cores: "{{ cpu_cores }}" | ||
54 | bios: "{{ bios_type }}" | ||
55 | ipconfig: | ||
56 | ipconfig0: "ip={{ ip_addr }},gw={{ gateway }}" | ||
57 | net: | ||
58 | net0: "virtio,bridge={{ vm_bridge }},tag={{ vm_vlan }}" | ||
59 | nameservers: "{{ nameserver }}" | ||
60 | onboot: "{{ vm_onboot }}" | ||
61 | agent: "{{ vm_agent }}" | ||
62 | state: present | ||
63 | |||
64 | - name: start vmn | ||
65 | become: yes | ||
66 | become_user: "{{ proxmox_username }}" | ||
67 | community.general.proxmox_kvm: | ||
68 | api_host: proxmox.home.local | ||
69 | api_user: "{{ proxmox_api_user }}" | ||
70 | api_token_id: "ansible" | ||
71 | api_token_secret: "{{ api_token.stdout }}" | ||
72 | node: proxmox | ||
73 | vmid: "{{ vm_id }}" | ||
74 | state: started | ||
75 | |||
76 | - name: remove api token | ||
77 | command: "pveum user token remove vmadmin@pam ansible" | ||
78 | register: result | ||
79 | changed_when: result.rc == 0 | ||
80 | failed_when: result.rc not in [0,255] | ||