Compare commits
31 Commits
54d26948bd
...
initial-vm
Author | SHA1 | Date | |
---|---|---|---|
72a790c038
|
|||
dfcfe941cf
|
|||
ac3494efc5
|
|||
6b2a820282
|
|||
6dfab582c4
|
|||
41a0c9393e
|
|||
92fbca47db
|
|||
5b0bae4865
|
|||
bc59bd5fdb
|
|||
8b128060e3
|
|||
870e4e9476
|
|||
763958634e
|
|||
29906fc462
|
|||
ab54c18b1b
|
|||
fce7d91115
|
|||
20bee24b19
|
|||
f891d1e6a8
|
|||
8406db7eaf
|
|||
2d8ad8f453
|
|||
599931fd9a
|
|||
0edaee542f
|
|||
b39d99b781
|
|||
9c2ce06cb0
|
|||
18e2ba2f75
|
|||
04881f9dfa
|
|||
19247a2467
|
|||
e12565fdb6
|
|||
52c0492176
|
|||
0dccf1902a
|
|||
1c59a98ec5
|
|||
7582010748
|
9
.github/workflows/infra.yaml
vendored
9
.github/workflows/infra.yaml
vendored
@@ -24,13 +24,10 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
fetch-depth: ${{ env.DEPLOY == 'some' && 2 || 1 }}
|
fetch-depth: ${{ env.DEPLOY == 'some' && 2 || 1 }}
|
||||||
|
|
||||||
- name: Setup Python
|
|
||||||
uses: actions/setup-python@v4
|
|
||||||
with:
|
|
||||||
python-version: "3.11"
|
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: |
|
run: |
|
||||||
|
apt update
|
||||||
|
apt install -y python3-pip
|
||||||
pip3 install -r requirements.txt
|
pip3 install -r requirements.txt
|
||||||
ansible-galaxy collection install community.general
|
ansible-galaxy collection install community.general
|
||||||
|
|
||||||
@@ -75,4 +72,4 @@ jobs:
|
|||||||
PROXMOX_TOKEN_ID: ${{ secrets.PROXMOX_TOKEN_ID }}
|
PROXMOX_TOKEN_ID: ${{ secrets.PROXMOX_TOKEN_ID }}
|
||||||
PROXMOX_TOKEN_SECRET: ${{ secrets.PROXMOX_TOKEN_SECRET }}
|
PROXMOX_TOKEN_SECRET: ${{ secrets.PROXMOX_TOKEN_SECRET }}
|
||||||
SSH_PUBLIC: ${{ secrets.SSH_PUBLIC }}
|
SSH_PUBLIC: ${{ secrets.SSH_PUBLIC }}
|
||||||
run: ansible-playbook --inventory ./inventory ${{ steps.playbooks.outputs.to_run }} -vvv
|
run: ansible-playbook --inventory ./inventory ${{ steps.playbooks.outputs.to_run }}
|
||||||
|
@@ -1,12 +1,14 @@
|
|||||||
- name: Provision joplin Proxmox VM
|
- name: Provision joplin Proxmox VM
|
||||||
hosts: localhost
|
hosts: joplin
|
||||||
|
connection: ansible.builtin.local
|
||||||
|
gather_facts: false
|
||||||
vars:
|
vars:
|
||||||
api_user: "{{ lookup('ansible.builtin.env', 'PROXMOX_USER') }}"
|
api_user: "{{ lookup('ansible.builtin.env', 'PROXMOX_USER') }}"
|
||||||
api_host: "{{ lookup('ansible.builtin.env', 'PROXMOX_HOST' ) }}"
|
api_host: "{{ lookup('ansible.builtin.env', 'PROXMOX_HOST' ) }}"
|
||||||
api_token_id: "{{ lookup('ansible.builtin.env', 'PROXMOX_TOKEN_ID') }}"
|
api_token_id: "{{ lookup('ansible.builtin.env', 'PROXMOX_TOKEN_ID') }}"
|
||||||
api_token_secret: "{{ lookup('ansible.builtin.env', 'PROXMOX_TOKEN_SECRET') }}"
|
api_token_secret: "{{ lookup('ansible.builtin.env', 'PROXMOX_TOKEN_SECRET') }}"
|
||||||
ssh_public: "{{ lookup('ansible.builtin.env', 'SSH_PUBLIC') }}"
|
ssh_public: "{{ lookup('ansible.builtin.env', 'SSH_PUBLIC') }}"
|
||||||
vmname: joplin
|
vmname: "{{ inventory_hostname | regex_replace('^([^\\.]+)\\..+$', '\\1') }}"
|
||||||
node: pve
|
node: pve
|
||||||
module_defaults:
|
module_defaults:
|
||||||
community.general.proxmox_kvm:
|
community.general.proxmox_kvm:
|
||||||
@@ -29,17 +31,21 @@
|
|||||||
api_token_secret: "{{ api_token_secret }}"
|
api_token_secret: "{{ api_token_secret }}"
|
||||||
name: "{{ vmname }}"
|
name: "{{ vmname }}"
|
||||||
tasks:
|
tasks:
|
||||||
|
# Initial setup
|
||||||
- name: Create VM
|
- name: Create VM
|
||||||
community.general.proxmox_kvm:
|
community.general.proxmox_kvm:
|
||||||
clone: "{{ node }}-debian-12"
|
clone: "{{ node }}-debian-12"
|
||||||
storage: nvme
|
storage: nvme
|
||||||
- name: Wait for VM to exist
|
register: create
|
||||||
|
- name: Wait for status
|
||||||
community.general.proxmox_kvm:
|
community.general.proxmox_kvm:
|
||||||
state: current
|
state: current
|
||||||
register: vm
|
register: vm
|
||||||
retries: 30
|
retries: 30
|
||||||
delay: 10
|
delay: 10
|
||||||
until: vm.status is defined
|
until: vm.status is defined
|
||||||
|
|
||||||
|
# Networking and initial config
|
||||||
- name: Add HOME NIC
|
- name: Add HOME NIC
|
||||||
community.general.proxmox_nic:
|
community.general.proxmox_nic:
|
||||||
interface: net0
|
interface: net0
|
||||||
@@ -50,6 +56,32 @@
|
|||||||
interface: net1
|
interface: net1
|
||||||
firewall: false
|
firewall: false
|
||||||
bridge: SRV
|
bridge: SRV
|
||||||
|
- name: Configure cloud-init
|
||||||
|
community.general.proxmox_kvm:
|
||||||
|
update: true
|
||||||
|
ciuser: debian
|
||||||
|
sshkeys: "{{ ssh_public }}"
|
||||||
|
ipconfig:
|
||||||
|
ipconfig0: ip=dhcp,ip6=auto
|
||||||
|
ipconfig1: ip=dhcp
|
||||||
|
|
||||||
|
# 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 ¯\_(ツ)_/¯
|
||||||
|
- name: Initial boot
|
||||||
|
when: create.changed is true
|
||||||
|
block:
|
||||||
|
- name: Start
|
||||||
|
community.general.proxmox_kvm:
|
||||||
|
state: started
|
||||||
|
register: start
|
||||||
|
- name: Wait 3 min # Initial apt update, apt upgrade, cloud-init
|
||||||
|
ansible.builtin.wait_for:
|
||||||
|
timeout: 180
|
||||||
|
|
||||||
|
# VM Configuration
|
||||||
- name: Resize disk
|
- name: Resize disk
|
||||||
community.general.proxmox_disk:
|
community.general.proxmox_disk:
|
||||||
disk: scsi0
|
disk: scsi0
|
||||||
@@ -58,11 +90,6 @@
|
|||||||
- name: Update VM
|
- name: Update VM
|
||||||
community.general.proxmox_kvm:
|
community.general.proxmox_kvm:
|
||||||
update: true
|
update: true
|
||||||
ciuser: debian
|
|
||||||
sshkeys: "{{ ssh_public }}"
|
|
||||||
ipconfig:
|
|
||||||
ipconfig0: ip=dhcp,ip6=auto
|
|
||||||
ipconfig1: ip=dhcp,ip6=auto
|
|
||||||
agent: enabled=1
|
agent: enabled=1
|
||||||
tags:
|
tags:
|
||||||
- debian-12
|
- debian-12
|
||||||
@@ -70,16 +97,8 @@
|
|||||||
onboot: true
|
onboot: true
|
||||||
cores: 2
|
cores: 2
|
||||||
memory: 2048
|
memory: 2048
|
||||||
- name: Retart VM # doesn't start if stopped
|
|
||||||
when:
|
- name: Retart VM
|
||||||
- vm.status is defined
|
|
||||||
- vm.status == "running"
|
|
||||||
community.general.proxmox_kvm:
|
community.general.proxmox_kvm:
|
||||||
state: restarted
|
state: restarted
|
||||||
timeout: 60
|
timeout: 60
|
||||||
- name: Start VM # start if stopped
|
|
||||||
when:
|
|
||||||
- vm.status is defined
|
|
||||||
- vm.status != "running"
|
|
||||||
community.general.proxmox_kvm:
|
|
||||||
state: started
|
|
||||||
|
@@ -2,19 +2,24 @@
|
|||||||
hosts: joplin
|
hosts: joplin
|
||||||
gather_facts: false
|
gather_facts: false
|
||||||
tasks:
|
tasks:
|
||||||
- name: Debug
|
|
||||||
ansible.builtin.debug:
|
|
||||||
msg: "{{ inventory_hostname }}"
|
|
||||||
- name: Wait for connection
|
- name: Wait for connection
|
||||||
ansible.builtin.wait_for:
|
ansible.builtin.wait_for_connection:
|
||||||
host: "{{ inventory_hostname }}"
|
|
||||||
port: 22
|
|
||||||
timeout: 300
|
timeout: 300
|
||||||
delegate_to: localhost
|
|
||||||
- name: Test some stuff
|
- name: Test some stuff
|
||||||
ansible.builtin.shell: |
|
ansible.builtin.shell: |
|
||||||
touch ~/hmm
|
touch ~/hmm
|
||||||
echo test > ~/test
|
echo test > ~/test
|
||||||
echo test2 >> ~/test
|
echo test2 >> ~/test
|
||||||
args:
|
mkdir ~/dir
|
||||||
executable: /bin/bash
|
touch ~/dir/testing
|
||||||
|
- name: Install some stuff
|
||||||
|
ansible.builtin.apt:
|
||||||
|
update_cache: true
|
||||||
|
name: qemu-guest-agent
|
||||||
|
become: true
|
||||||
|
- name: Enable some stuff
|
||||||
|
ansible.builtin.systemd:
|
||||||
|
name: qemu-guest-agent
|
||||||
|
state: started
|
||||||
|
enabled: true
|
||||||
|
become: true
|
||||||
|
@@ -10,7 +10,7 @@ proxmox:
|
|||||||
children:
|
children:
|
||||||
joplin:
|
joplin:
|
||||||
hosts:
|
hosts:
|
||||||
joplin.srv.home.local.koval.net:
|
joplin2.srv.home.local.koval.net:
|
||||||
vars:
|
vars:
|
||||||
ansible_user: debian
|
ansible_user: debian
|
||||||
ansible_ssh_private_key_file: ~/.ssh/id_rsa
|
ansible_ssh_private_key_file: ~/.ssh/id_rsa
|
||||||
|
Reference in New Issue
Block a user