Compare commits
4 commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c6cff38e59 | |||
| d799507b6c | |||
| beab8fedc6 | |||
| 32d407c6af |
6 changed files with 44 additions and 62 deletions
|
|
@ -17,16 +17,12 @@ jobs:
|
|||
NIXOS_BUILER_USER: runner
|
||||
PROXMOX_HOST: 192.168.1.205
|
||||
PROXMOX_USER: plasmagoat
|
||||
|
||||
# VM Template IDs for your Ansible playbook
|
||||
# These are now passed to the playbook via --extra-vars, not directly as env vars for qm.
|
||||
# They are defined in group_vars/all.yml, but can be overridden from here if needed.
|
||||
# TEMPLATE_VMID: 9001 # Removed from direct env for explicit passing to Ansible
|
||||
# LATEST_TEMPLATE_VMID: 9000 # Removed from direct env for explicit passing to Ansible
|
||||
outputs:
|
||||
image-name: ${{ steps.build_image.outputs.image_name_from_build }}
|
||||
flake-metadata: ${{ steps.meta.outputs.metadata }}
|
||||
image-version: ${{ steps.version.outputs.tag_name }}
|
||||
image-url: ${{ steps.image-artifact.outputs.artifact-url }}
|
||||
flake-metadata: ${{ steps.meta.outputs.metadata }}
|
||||
|
||||
steps:
|
||||
# Use nix-env for setup (as you prefer and it works well for ephemeral environments)
|
||||
- name: Install dependencies via nix-env
|
||||
|
|
@ -89,26 +85,31 @@ jobs:
|
|||
echo "image_path_from_build=${IMAGE_PATH}" >> "$GITHUB_OUTPUT"
|
||||
echo "image_name_from_build=${IMAGE_NAME}" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Set version
|
||||
id: version
|
||||
run: |
|
||||
if [[ "${{ github.ref_type }}" == "tag" ]]; then
|
||||
TAG_NAME="${{ github.ref_name }}"
|
||||
else
|
||||
TAG_NAME="dev-$(date +%Y%m%d)-${GITHUB_SHA::7}"
|
||||
fi
|
||||
echo "Ref Type: ${{ github.ref_type }}"
|
||||
echo "Ref Name: ${{ github.ref_name }}"
|
||||
echo "Version: $TAG_NAME"
|
||||
echo "tag_name=$TAG_NAME" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Run Proxmox Image Deployment
|
||||
run: |
|
||||
chmod +x ./scripts/run_ansible_ci.sh
|
||||
# Execute the script, passing necessary environment variables
|
||||
bash scripts/run_ansible_ci.sh
|
||||
env:
|
||||
# These are passed directly to the `run_ansible_ci.sh` script,
|
||||
# which then uses them to construct Ansible's --extra-vars.
|
||||
# Match these variable names with what `run_ansible_ci.sh` expects.
|
||||
# Note: The `image_path_from_build` comes from the previous step's output.
|
||||
PROXMOX_LOCAL_IMAGE_PATH_FROM_BUILD: ${{ steps.build_image.outputs.image_path_from_build }}
|
||||
|
||||
# Provide VMIDs and names, overriding group_vars if desired.
|
||||
# These will be passed as `--extra-vars` to Ansible.
|
||||
ANSIBLE_EXTRA_VARS: >-
|
||||
backup_template_vmid={{ env.TEMPLATE_VMID | default('9001') }}
|
||||
latest_template_vmid={{ env.LATEST_TEMPLATE_VMID | default('9000') }}
|
||||
proxmox_host={{ env.PROXMOX_HOST }}
|
||||
proxmox_user={{ env.PROXMOX_USER }}
|
||||
remote_image_path_ci={{ steps.build_image.outputs.image_path_from_build }}
|
||||
backup_template_vmid=${{ env.TEMPLATE_VMID | default('9001') }}
|
||||
latest_template_vmid=${{ env.LATEST_TEMPLATE_VMID | default('9000') }}
|
||||
version=${{ steps.version.outputs.tag_name }}
|
||||
|
||||
- name: Extract flake metadata
|
||||
id: meta
|
||||
|
|
@ -153,25 +154,12 @@ jobs:
|
|||
with:
|
||||
name: release-artifact
|
||||
|
||||
- name: Set version
|
||||
id: version
|
||||
run: |
|
||||
if [[ "${{ github.ref_type }}" == "tag" ]]; then
|
||||
TAG_NAME="${{ github.ref_name }}"
|
||||
else
|
||||
TAG_NAME="dev-$(date +%Y%m%d)-${GITHUB_SHA::7}"
|
||||
fi
|
||||
echo "Ref Type: ${{ github.ref_type }}"
|
||||
echo "Ref Name: ${{ github.ref_name }}"
|
||||
echo "Version: $TAG_NAME"
|
||||
echo "tag_name=$TAG_NAME" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Create Forgejo Release
|
||||
uses: https://code.forgejo.org/sheik/forgejo-release@v2.6.0
|
||||
with:
|
||||
title: "NixOS Base Image ${{ steps.version.outputs.tag_name }}"
|
||||
title: "NixOS Base Image ${{ needs.build.outputs.image-version }}"
|
||||
prerelease: ${{ github.ref_type != 'tag' }}
|
||||
tag: ${{ steps.version.outputs.tag_name }}
|
||||
tag: ${{ needs.build.outputs.image-version }}
|
||||
direction: upload
|
||||
release-notes: |
|
||||
✅ **Base NixOS image uploaded**
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
# Nixs base image for promxox
|
||||
# NixOS base image for promxox
|
||||
This is the nixos base image to be used as a template in proxmox
|
||||
|
||||
## Using this base image
|
||||
|
|
@ -12,6 +12,6 @@ nix build .#base
|
|||
Copy to target proxmox storage
|
||||
|
||||
```bash
|
||||
cd ansible
|
||||
ansible-playbook upload-template.yml
|
||||
chmod +x scripts/run_ansible_ci.sh
|
||||
./scripts/run_ansible_ci.sh
|
||||
```
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
---
|
||||
all:
|
||||
children:
|
||||
proxmox:
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@
|
|||
- name: Restore VM from image to 'latest' template VMID
|
||||
ansible.builtin.shell: |
|
||||
qmrestore {{ remote_image_path }} {{ vmid_latest_template }} --unique true --storage {{ storage_name }}
|
||||
qm set {{ vmid_latest_template }} --cores {{ cpu_cores }} --memory {{ memory_mb }} --name {{ vmname_latest_template }}
|
||||
qm set {{ vmid_latest_template }} --cores {{ cpu_cores }} --memory {{ memory_mb }} --name {{ vmname_latest_template }} --tag {{ template_version }}
|
||||
qm template {{ vmid_latest_template }}
|
||||
register: restore_new_latest_result
|
||||
changed_when: restore_new_latest_result.rc == 0
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
vmname_backup_template: "{{ backup_template_vm_name }}"
|
||||
vmid_latest_template: "{{ latest_template_vmid }}"
|
||||
vmname_latest_template: "{{ latest_template_vm_name }}"
|
||||
template_version: "{{ version | default('v0.0.0') }}"
|
||||
|
||||
roles:
|
||||
- role: create-template
|
||||
|
|
|
|||
|
|
@ -3,12 +3,6 @@ set -euo pipefail
|
|||
|
||||
echo "Starting Ansible CI/CD run..."
|
||||
|
||||
# # --- 1. Validate required environment variables ---
|
||||
# if [[ -z "${PROXMOX_LOCAL_IMAGE_PATH_FROM_BUILD}" ]]; then
|
||||
# echo "Error: PROXMOX_LOCAL_IMAGE_PATH_FROM_BUILD environment variable not set. Cannot find built image."
|
||||
# exit 1
|
||||
# fi
|
||||
|
||||
# --- 2. Navigate to the Ansible directory ---
|
||||
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd -P)
|
||||
ANSIBLE_DIR="${SCRIPT_DIR}/../ansible"
|
||||
|
|
@ -23,32 +17,32 @@ echo "Changed directory to: $(pwd)"
|
|||
|
||||
# # --- 3. Define Ansible Extra Variables ---
|
||||
# # Base extra variables from our static definitions
|
||||
# EXTRA_VARS=(
|
||||
# # "local_image_path_ci=${PROXMOX_LOCAL_IMAGE_PATH_FROM_BUILD}" # Path to the image file on the CI runner
|
||||
# # "image_filename=$(basename "${PROXMOX_LOCAL_IMAGE_PATH_FROM_BUILD}")" # Extract filename
|
||||
# )
|
||||
EXTRA_VARS=(
|
||||
# "local_image_path_ci=${PROXMOX_LOCAL_IMAGE_PATH_FROM_BUILD}" # Path to the image file on the CI runner
|
||||
# "image_filename=$(basename "${PROXMOX_LOCAL_IMAGE_PATH_FROM_BUILD}")" # Extract filename
|
||||
)
|
||||
|
||||
# # Append any other variables passed via ANSIBLE_EXTRA_VARS from the workflow
|
||||
# if [[ -n "${ANSIBLE_EXTRA_VARS:-}" ]]; then
|
||||
# # Split by space or newline and add to array
|
||||
# IFS=$'\n' read -r -d '' -a ADDITIONAL_VARS <<< "${ANSIBLE_EXTRA_VARS}" || true
|
||||
# for var in "${ADDITIONAL_VARS[@]}"; do
|
||||
# EXTRA_VARS+=("${var}")
|
||||
# done
|
||||
# fi
|
||||
if [[ -n "${ANSIBLE_EXTRA_VARS:-}" ]]; then
|
||||
# Split by space or newline and add to array
|
||||
IFS=$'\n' read -r -d '' -a ADDITIONAL_VARS <<< "${ANSIBLE_EXTRA_VARS}" || true
|
||||
for var in "${ADDITIONAL_VARS[@]}"; do
|
||||
EXTRA_VARS+=("${var}")
|
||||
done
|
||||
fi
|
||||
|
||||
# # --- 4. Execute the Ansible Playbook ---
|
||||
# echo "Executing Ansible playbook: upload-template.yml"
|
||||
|
||||
# # Construct the full --extra-vars string
|
||||
# EXTRA_VARS_ARGS=""
|
||||
# for var in "${EXTRA_VARS[@]}"; do
|
||||
# EXTRA_VARS_ARGS+=" -e ${var}"
|
||||
# done
|
||||
EXTRA_VARS_ARGS=""
|
||||
for var in "${EXTRA_VARS[@]}"; do
|
||||
EXTRA_VARS_ARGS+=" -e ${var}"
|
||||
done
|
||||
|
||||
ansible-playbook upload-template.yml #\
|
||||
# --inventory inventory/hosts.yml \
|
||||
# ${EXTRA_VARS_ARGS} \
|
||||
ansible-playbook upload-template.yml \
|
||||
--inventory inventory/hosts.yml \
|
||||
${EXTRA_VARS_ARGS} # \
|
||||
# --diff \
|
||||
# --check false # Set to true for a dry run, false for actual execution
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue