blob: 23a0b6192b99db5149fe8bbd7eea267e25247087 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
---
- name: download template
command: "pveam download local {{ flavors[proxmox.flavor].template }}_amd64.tar.xz"
args:
creates: "/var/lib/vz/template/cache/{{ flavors[proxmox.flavor].template }}_amd64.tar.xz"
delegate_to: "{{ proxmox.host }}"
- name: create host
command: >
pct create {{ proxmox.id }} "/var/lib/vz/template/cache/{{ flavors[proxmox.flavor].template }}_amd64.tar.xz"
--hostname {{ inventory_hostname }}
--storage local-zfs
-net0 name=eth0,bridge=vmbr0,ip=dhcp
-onboot 1
{% if not proxmox.privileged|default(false) %} -unprivileged {% endif %}
{% if proxmox.features|default(None) %} -features {{ proxmox.features }} {% endif %}
-memory {{ proxmox.memory|default(1024) }}
{% for disk in proxmox.disks|default([]) %}
--mp{{ disk.index }} volume={{ disk.storage }}:{{ disk.size_gb }},mp={{ disk.path }}
{% endfor %}
-rootfs local-zfs:{{ proxmox.disk|default(4) }}
--password {{ ansible_password|trim }}
--nameserver {{ hostvars[proxmox.host].network.self_internal_ip }}
--ostype {{ flavors[proxmox.flavor].pct_ostype }}
args:
creates: "/etc/pve/lxc/{{ proxmox.id }}.conf"
delegate_to: "{{ proxmox.host }}"
- name: allow backups
shell: "zfs allow -u backups mount,send,hold,snapshot,destroy rpool/data/$(pct config {{ proxmox.id }} | grep mp{{ item.index }} | cut -d , -f 1 | cut -d : -f 3)"
delegate_to: "{{ proxmox.host }}"
loop: "{{ proxmox.disks|default([]) }}"
- name: proxmox extra
when: proxmox.extra|default(None)
block:
- name: set proxmox extra copy out
copy:
remote_src: yes
src: /etc/pve/lxc/{{ proxmox.id }}.conf
dest: /tmp/{{ proxmox.id }}.conf
delegate_to: "{{ proxmox.host }}"
- name: read conf
slurp:
src: /tmp/{{ proxmox.id }}.conf
register: proxmox_conf
delegate_to: "{{ proxmox.host }}"
- name: set proxmox extra
lineinfile:
path: /tmp/{{ proxmox.id }}.conf
line: "{{ item }}"
loop: "{{ proxmox.extra }}"
delegate_to: "{{ proxmox.host }}"
- name: set proxmox extra copy in
command: cp /tmp/{{ proxmox.id }}.conf /etc/pve/lxc/{{ proxmox.id }}.conf
delegate_to: "{{ proxmox.host }}"
- name: start host
shell: "{ pct status {{ proxmox.id }} | grep running ; } || pct start {{ proxmox.id }}"
delegate_to: "{{ proxmox.host }}"
- name: update packages to prevent automatic updates causing issues later. retry until network available
command: pct exec {{ proxmox.id }} -- dnf update -y
retries: 10
delay: 1
until: result.rc == 0
register: result
delegate_to: "{{ proxmox.host }}"
- name: install ssh
command: pct exec {{ proxmox.id }} -- dnf install -y openssh-server
delegate_to: "{{ proxmox.host }}"
- name: permit root password
lineinfile:
path: /rpool/data/subvol-{{ proxmox.id }}-disk-0/etc/ssh/sshd_config
regexp: "^#?PermitRootLogin"
line: "PermitRootLogin yes"
delegate_to: "{{ proxmox.host }}"
- name: enable ssh
command: pct exec {{ proxmox.id }} -- systemctl enable --now sshd
delegate_to: "{{ proxmox.host }}"
|