Compare commits
33 Commits
f447e9e77e
...
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
|
|||
54d26948bd
|
|||
46de0b3d0f
|
11
.github/workflows/infra.yaml
vendored
11
.github/workflows/infra.yaml
vendored
@@ -24,13 +24,10 @@ jobs:
|
||||
with:
|
||||
fetch-depth: ${{ env.DEPLOY == 'some' && 2 || 1 }}
|
||||
|
||||
- name: Setup Python
|
||||
uses: actions/setup-python@v4
|
||||
with:
|
||||
python-version: "3.11"
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
apt update
|
||||
apt install -y python3-pip
|
||||
pip3 install -r requirements.txt
|
||||
ansible-galaxy collection install community.general
|
||||
|
||||
@@ -66,8 +63,6 @@ jobs:
|
||||
mkdir -p -m 700 ~/.ssh
|
||||
echo "${{ secrets.SSH_PRIVATE }}" > ~/.ssh/id_rsa
|
||||
chmod 600 ~/.ssh/id_rsa
|
||||
cat ~/.ssh/id_rsa | wc -c
|
||||
cat ~/.ssh/id_rsa | wc -l
|
||||
|
||||
- name: Run playbooks
|
||||
if: env.DEPLOY != 'none' && steps.playbooks.outputs.to_run != ''
|
||||
@@ -77,4 +72,4 @@ jobs:
|
||||
PROXMOX_TOKEN_ID: ${{ secrets.PROXMOX_TOKEN_ID }}
|
||||
PROXMOX_TOKEN_SECRET: ${{ secrets.PROXMOX_TOKEN_SECRET }}
|
||||
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
|
||||
hosts: localhost
|
||||
hosts: joplin
|
||||
connection: ansible.builtin.local
|
||||
gather_facts: false
|
||||
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') }}"
|
||||
vmname: joplin
|
||||
vmname: "{{ inventory_hostname | regex_replace('^([^\\.]+)\\..+$', '\\1') }}"
|
||||
node: pve
|
||||
module_defaults:
|
||||
community.general.proxmox_kvm:
|
||||
@@ -29,17 +31,21 @@
|
||||
api_token_secret: "{{ api_token_secret }}"
|
||||
name: "{{ vmname }}"
|
||||
tasks:
|
||||
# Initial setup
|
||||
- name: Create VM
|
||||
community.general.proxmox_kvm:
|
||||
clone: "{{ node }}-debian-12"
|
||||
storage: nvme
|
||||
- name: Wait for VM to exist
|
||||
register: create
|
||||
- name: Wait for status
|
||||
community.general.proxmox_kvm:
|
||||
state: current
|
||||
register: vm
|
||||
retries: 30
|
||||
delay: 10
|
||||
until: vm.status is defined
|
||||
|
||||
# Networking and initial config
|
||||
- name: Add HOME NIC
|
||||
community.general.proxmox_nic:
|
||||
interface: net0
|
||||
@@ -50,6 +56,32 @@
|
||||
interface: net1
|
||||
firewall: false
|
||||
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
|
||||
community.general.proxmox_disk:
|
||||
disk: scsi0
|
||||
@@ -58,11 +90,6 @@
|
||||
- name: Update VM
|
||||
community.general.proxmox_kvm:
|
||||
update: true
|
||||
ciuser: debian
|
||||
sshkeys: "{{ ssh_public }}"
|
||||
ipconfig:
|
||||
ipconfig0: ip=dhcp,ip6=auto
|
||||
ipconfig1: ip=dhcp,ip6=auto
|
||||
agent: enabled=1
|
||||
tags:
|
||||
- debian-12
|
||||
@@ -70,16 +97,8 @@
|
||||
onboot: true
|
||||
cores: 2
|
||||
memory: 2048
|
||||
- name: Retart VM # doesn't start if stopped
|
||||
when:
|
||||
- vm.status is defined
|
||||
- vm.status == "running"
|
||||
|
||||
- name: Retart VM
|
||||
community.general.proxmox_kvm:
|
||||
state: restarted
|
||||
timeout: 60
|
||||
- name: Start VM # start if stopped
|
||||
when:
|
||||
- vm.status is defined
|
||||
- vm.status != "running"
|
||||
community.general.proxmox_kvm:
|
||||
state: started
|
||||
|
@@ -2,26 +2,24 @@
|
||||
hosts: joplin
|
||||
gather_facts: false
|
||||
tasks:
|
||||
- name: Debug
|
||||
ansible.builtin.debug:
|
||||
msg: "{{ inventory_hostname }}"
|
||||
- name: Wut
|
||||
ansible.builtin.shell: |
|
||||
apt update
|
||||
apt install -y iputils-ping
|
||||
ping -c 5 {{ inventory_hostname }}
|
||||
args:
|
||||
executable: /bin/bash
|
||||
delegate_to: localhost
|
||||
- name: Wait for connection
|
||||
ansible.builtin.wait_for:
|
||||
host: "{{ inventory_hostname }}"
|
||||
port: 22
|
||||
ansible.builtin.wait_for_connection:
|
||||
timeout: 300
|
||||
- name: Test some stuff
|
||||
ansible.builtin.shell: |
|
||||
touch ~/hmm
|
||||
echo test > ~/test
|
||||
echo test2 >> ~/test
|
||||
args:
|
||||
executable: /bin/bash
|
||||
mkdir ~/dir
|
||||
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:
|
||||
joplin:
|
||||
hosts:
|
||||
joplin.srv.home.local.koval.net:
|
||||
joplin2.srv.home.local.koval.net:
|
||||
vars:
|
||||
ansible_user: debian
|
||||
ansible_ssh_private_key_file: ~/.ssh/id_rsa
|
||||
|
Reference in New Issue
Block a user