2023-09-04 18:59:57 +00:00
|
|
|
- name: Provision joplin Proxmox VM
|
2023-09-06 22:39:19 +00:00
|
|
|
hosts: joplin
|
2023-09-06 00:35:34 +00:00
|
|
|
connection: ansible.builtin.local
|
2023-09-08 23:00:30 +00:00
|
|
|
gather_facts: false
|
2023-09-04 18:59:57 +00:00
|
|
|
vars:
|
|
|
|
api_user: "{{ lookup('ansible.builtin.env', 'PROXMOX_USER') }}"
|
|
|
|
api_host: "{{ lookup('ansible.builtin.env', 'PROXMOX_HOST' ) }}"
|
|
|
|
api_token_id: "{{ lookup('ansible.builtin.env', 'PROXMOX_TOKEN_ID') }}"
|
|
|
|
api_token_secret: "{{ lookup('ansible.builtin.env', 'PROXMOX_TOKEN_SECRET') }}"
|
|
|
|
ssh_public: "{{ lookup('ansible.builtin.env', 'SSH_PUBLIC') }}"
|
2023-09-06 00:35:34 +00:00
|
|
|
vmname: "{{ inventory_hostname | regex_replace('^([^\\.]+)\\..+$', '\\1') }}"
|
2023-09-04 18:59:57 +00:00
|
|
|
node: pve
|
|
|
|
module_defaults:
|
|
|
|
community.general.proxmox_kvm:
|
|
|
|
api_user: "{{ api_user }}"
|
|
|
|
api_host: "{{ api_host }}"
|
|
|
|
api_token_id: "{{ api_token_id }}"
|
|
|
|
api_token_secret: "{{ api_token_secret }}"
|
|
|
|
name: "{{ vmname }}"
|
|
|
|
node: "{{ node }}"
|
|
|
|
community.general.proxmox_nic:
|
|
|
|
api_user: "{{ api_user }}"
|
|
|
|
api_host: "{{ api_host }}"
|
|
|
|
api_token_id: "{{ api_token_id }}"
|
|
|
|
api_token_secret: "{{ api_token_secret }}"
|
|
|
|
name: "{{ vmname }}"
|
|
|
|
community.general.proxmox_disk:
|
|
|
|
api_user: "{{ api_user }}"
|
|
|
|
api_host: "{{ api_host }}"
|
|
|
|
api_token_id: "{{ api_token_id }}"
|
|
|
|
api_token_secret: "{{ api_token_secret }}"
|
|
|
|
name: "{{ vmname }}"
|
|
|
|
tasks:
|
2023-09-10 22:54:34 +00:00
|
|
|
# Initial setup
|
2023-09-04 18:59:57 +00:00
|
|
|
- name: Create VM
|
|
|
|
community.general.proxmox_kvm:
|
|
|
|
clone: "{{ node }}-debian-12"
|
|
|
|
storage: nvme
|
2023-09-10 22:12:18 +00:00
|
|
|
register: create
|
2023-09-10 22:54:34 +00:00
|
|
|
- name: Wait for status
|
|
|
|
community.general.proxmox_kvm:
|
|
|
|
state: current
|
|
|
|
register: vm
|
|
|
|
retries: 30
|
|
|
|
delay: 10
|
|
|
|
until: vm.status is defined
|
|
|
|
|
|
|
|
# Networking
|
|
|
|
- name: Add HOME NIC
|
|
|
|
community.general.proxmox_nic:
|
|
|
|
interface: net0
|
|
|
|
firewall: false
|
|
|
|
bridge: HOME
|
|
|
|
- name: Add SRV NIC
|
|
|
|
community.general.proxmox_nic:
|
|
|
|
interface: net1
|
|
|
|
firewall: false
|
|
|
|
bridge: SRV
|
|
|
|
|
|
|
|
# Initial boot
|
|
|
|
# For some reason debian cloud images don't use
|
|
|
|
# cloud-init for networking on first boot (cloud-init files
|
|
|
|
# are regenerated AFTER networking starts). But we need the
|
|
|
|
# hostname to be registered with DHCP later on so ¯\_(ツ)_/¯
|
2023-09-10 22:42:26 +00:00
|
|
|
- name: Initial boot
|
|
|
|
when: create.changed is true
|
|
|
|
block:
|
|
|
|
- name: Start
|
|
|
|
community.general.proxmox_kvm:
|
|
|
|
state: started
|
|
|
|
register: start
|
2023-09-10 22:54:34 +00:00
|
|
|
- name: Wait # Initial apt update, apt upgrade, cloud-init
|
2023-09-10 22:42:26 +00:00
|
|
|
ansible.builtin.wait_for:
|
2023-09-10 23:43:36 +00:00
|
|
|
timeout: 90
|
2023-09-10 22:54:34 +00:00
|
|
|
|
|
|
|
# VM Configuration
|
2023-09-04 18:59:57 +00:00
|
|
|
- name: Resize disk
|
|
|
|
community.general.proxmox_disk:
|
|
|
|
disk: scsi0
|
|
|
|
size: 64G
|
|
|
|
state: resized
|
|
|
|
- name: Update VM
|
|
|
|
community.general.proxmox_kvm:
|
|
|
|
update: true
|
|
|
|
ciuser: debian
|
|
|
|
sshkeys: "{{ ssh_public }}"
|
|
|
|
ipconfig:
|
|
|
|
ipconfig0: ip=dhcp,ip6=auto
|
2023-09-08 22:58:04 +00:00
|
|
|
ipconfig1: ip=dhcp
|
2023-09-04 18:59:57 +00:00
|
|
|
agent: enabled=1
|
|
|
|
tags:
|
|
|
|
- debian-12
|
|
|
|
- managed
|
|
|
|
onboot: true
|
|
|
|
cores: 2
|
|
|
|
memory: 2048
|
2023-09-10 22:54:34 +00:00
|
|
|
|
2023-09-10 23:07:56 +00:00
|
|
|
- name: Retart VM
|
2023-09-04 18:59:57 +00:00
|
|
|
community.general.proxmox_kvm:
|
|
|
|
state: restarted
|
|
|
|
timeout: 60
|