From 7db11c65068a4efa8656830ee84f6d84a322e57e Mon Sep 17 00:00:00 2001 From: Gleb Koval Date: Sat, 2 Sep 2023 17:54:03 +0000 Subject: [PATCH] infra-setup (#2) Reviewed-on: https://git.koval.net/cyclane/kovalhome/pulls/2 --- .github/workflows/infra.yaml | 65 +++++++++++++++++++++++++++++ README.md | 1 - infra/test-vm/proxmox-playbook.yaml | 24 +++++++++++ inventory/proxmox.yaml | 13 ++++++ 4 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/infra.yaml delete mode 100644 README.md create mode 100644 infra/test-vm/proxmox-playbook.yaml create mode 100644 inventory/proxmox.yaml diff --git a/.github/workflows/infra.yaml b/.github/workflows/infra.yaml new file mode 100644 index 0000000..b0b971a --- /dev/null +++ b/.github/workflows/infra.yaml @@ -0,0 +1,65 @@ +name: Infrastructure +on: + pull_request: + branches: + - main + push: + branches: + - main + tags: + - infra/** + paths: + - infra/**-playbook.yaml + - .github/workflows/infra.yaml + fork: + +jobs: + check: + name: Check infrastructure definitions + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Setup Python + uses: actions/setup-python@v4 + with: + python-version: "3.11" + + - name: Install dependencies + run: | + pip3 install -r requirements.txt + ansible-galaxy collection install community.general + + - name: Check modified playbooks + run: | + find . -wholename "*/infra/*-playbook.yaml" -type f -exec ansible-playbook --inventory ./inventory --check {} \; + deploy: + name: Deploy modified infrastructure + runs-on: ubuntu-latest + if: github.ref == 'refs/heads/main' + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 2 + + - name: Setup Python + uses: actions/setup-python@v4 + with: + python-version: "3.11" + + - name: Install dependencies + run: | + pip3 install -r requirements.txt + ansible-galaxy collection install community.general + + - name: Get changed files + id: files + uses: tj-actions/changed-files@v38 + + - name: Run changed playbooks + run: | + for file in ${{ steps.files.outputs.all_changed_files }}; do + ansible-playbook --inventory ./inventory "$file" + done diff --git a/README.md b/README.md deleted file mode 100644 index 7f0e2bd..0000000 --- a/README.md +++ /dev/null @@ -1 +0,0 @@ -# KovalHome (and koval.net) infrastructure diff --git a/infra/test-vm/proxmox-playbook.yaml b/infra/test-vm/proxmox-playbook.yaml new file mode 100644 index 0000000..e8c20bf --- /dev/null +++ b/infra/test-vm/proxmox-playbook.yaml @@ -0,0 +1,24 @@ +- name: Proxmox test-vm + hosts: localhost + module_defaults: + community.general.proxmox_kvm: + api_user: "{{ lookup('ansible.builtin.env', 'PROXMOX_TOKEN_ID') | regex_replace('!.*') }}" + api_host: "{{ lookup('ansible.builtin.env', 'PROXMOX_HOST' ) }}" + api_token_id: "{{ lookup('ansible.builtin.env', 'PROXMOX_TOKEN_ID') | regex_replace('.*!') }}" + api_token_secret: "{{ lookup('ansible.builtin.env', 'PROXMOX_TOKEN_SECRET') }}" + name: test-vm + node: pve + tasks: + - name: Create test-vm + community.general.proxmox_kvm: + name: test-vm + node: pve + - name: Update test-vm + community.general.proxmox_kvm: + cpu: x86-64-v3 + memory: 2048 + cores: 3 + update: true + - name: Start test-vm + community.general.proxmox_kvm: + state: started diff --git a/inventory/proxmox.yaml b/inventory/proxmox.yaml new file mode 100644 index 0000000..ff90334 --- /dev/null +++ b/inventory/proxmox.yaml @@ -0,0 +1,13 @@ +proxmox: + children: + kovalhome: + children: + nodes: + hosts: + pve.mgmt.home.local.koval.net: + pve2.mgmt.home.local.koval.net: + managed: + hosts: + test-vm.mgmt.home.local.koval.net: + unmanaged: + hosts: