Compare commits
3 Commits
11999b37f3
...
0cf72ec191
| Author | SHA1 | Date | |
|---|---|---|---|
|
0cf72ec191
|
|||
|
6a3a51407e
|
|||
|
a1ae766eb8
|
@@ -6,11 +6,18 @@ let
|
|||||||
text = ''
|
text = ''
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
|
# Clear screen and show bootstrap banner
|
||||||
|
clear
|
||||||
|
echo "================================================================================"
|
||||||
|
echo " NIXOS BOOTSTRAP IN PROGRESS"
|
||||||
|
echo "================================================================================"
|
||||||
|
echo ""
|
||||||
|
|
||||||
# Read hostname set by cloud-init (from Terraform VM name via user-data)
|
# Read hostname set by cloud-init (from Terraform VM name via user-data)
|
||||||
# Cloud-init sets the system hostname from user-data.txt, so we read it from hostnamectl
|
# Cloud-init sets the system hostname from user-data.txt, so we read it from hostnamectl
|
||||||
HOSTNAME=$(hostnamectl hostname)
|
HOSTNAME=$(hostnamectl hostname)
|
||||||
echo "DEBUG: Hostname from hostnamectl: '$HOSTNAME'"
|
echo "Hostname: $HOSTNAME"
|
||||||
|
echo ""
|
||||||
echo "Starting NixOS bootstrap for host: $HOSTNAME"
|
echo "Starting NixOS bootstrap for host: $HOSTNAME"
|
||||||
echo "Waiting for network connectivity..."
|
echo "Waiting for network connectivity..."
|
||||||
|
|
||||||
@@ -93,6 +100,21 @@ let
|
|||||||
};
|
};
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
|
# Custom greeting line to indicate this is a bootstrap image
|
||||||
|
services.getty.greetingLine = lib.mkForce ''
|
||||||
|
================================================================================
|
||||||
|
BOOTSTRAP IMAGE - NixOS \V (\l)
|
||||||
|
================================================================================
|
||||||
|
|
||||||
|
Bootstrap service is running. Logs are displayed on tty1.
|
||||||
|
Check status: journalctl -fu nixos-bootstrap
|
||||||
|
'';
|
||||||
|
|
||||||
|
# Disable getty on tty1 so bootstrap output is visible
|
||||||
|
systemd.services."getty@tty1" = {
|
||||||
|
enable = false;
|
||||||
|
};
|
||||||
|
|
||||||
systemd.services."nixos-bootstrap" = {
|
systemd.services."nixos-bootstrap" = {
|
||||||
description = "Bootstrap NixOS configuration from flake on first boot";
|
description = "Bootstrap NixOS configuration from flake on first boot";
|
||||||
|
|
||||||
@@ -107,14 +129,17 @@ in
|
|||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
Type = "oneshot";
|
Type = "oneshot";
|
||||||
RemainAfterExit = true;
|
RemainAfterExit = true;
|
||||||
ExecStart = "${bootstrap-script}/bin/nixos-bootstrap";
|
ExecStart = lib.getExe bootstrap-script;
|
||||||
|
|
||||||
# Read environment variables from cloud-init (set by cloud-init write_files)
|
# Read environment variables from cloud-init (set by cloud-init write_files)
|
||||||
EnvironmentFile = "-/run/cloud-init-env";
|
EnvironmentFile = "-/run/cloud-init-env";
|
||||||
|
|
||||||
# Logging to journald
|
# Output to tty1 for visibility on console
|
||||||
StandardOutput = "journal+console";
|
StandardOutput = "tty";
|
||||||
StandardError = "journal+console";
|
StandardError = "tty";
|
||||||
|
TTYPath = "/dev/tty1";
|
||||||
|
TTYReset = true;
|
||||||
|
TTYVHangup = true;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -99,3 +99,48 @@
|
|||||||
- name: Display success message
|
- name: Display success message
|
||||||
ansible.builtin.debug:
|
ansible.builtin.debug:
|
||||||
msg: "Template VM {{ template_vmid }} created successfully on {{ storage }}"
|
msg: "Template VM {{ template_vmid }} created successfully on {{ storage }}"
|
||||||
|
|
||||||
|
- name: Update Terraform template name
|
||||||
|
hosts: localhost
|
||||||
|
gather_facts: false
|
||||||
|
|
||||||
|
vars:
|
||||||
|
terraform_dir: "{{ playbook_dir }}/../terraform"
|
||||||
|
|
||||||
|
tasks:
|
||||||
|
- name: Get image filename from earlier play
|
||||||
|
ansible.builtin.set_fact:
|
||||||
|
image_filename: "{{ hostvars['localhost']['image_filename'] }}"
|
||||||
|
|
||||||
|
- name: Extract template name from image filename
|
||||||
|
ansible.builtin.set_fact:
|
||||||
|
new_template_name: "{{ image_filename | regex_replace('\\.vma\\.zst$', '') | regex_replace('^vzdump-qemu-', '') }}"
|
||||||
|
|
||||||
|
- name: Read current Terraform variables file
|
||||||
|
ansible.builtin.slurp:
|
||||||
|
src: "{{ terraform_dir }}/variables.tf"
|
||||||
|
register: variables_tf_content
|
||||||
|
|
||||||
|
- name: Extract current template name from variables.tf
|
||||||
|
ansible.builtin.set_fact:
|
||||||
|
current_template_name: "{{ (variables_tf_content.content | b64decode) | regex_search('variable \"default_template_name\"[^}]+default\\s*=\\s*\"([^\"]+)\"', '\\1') | first }}"
|
||||||
|
|
||||||
|
- name: Check if template name has changed
|
||||||
|
ansible.builtin.set_fact:
|
||||||
|
template_name_changed: "{{ current_template_name != new_template_name }}"
|
||||||
|
|
||||||
|
- name: Display template name status
|
||||||
|
ansible.builtin.debug:
|
||||||
|
msg: "Template name: {{ current_template_name }} -> {{ new_template_name }} ({{ 'changed' if template_name_changed else 'unchanged' }})"
|
||||||
|
|
||||||
|
- name: Update default_template_name in variables.tf
|
||||||
|
ansible.builtin.replace:
|
||||||
|
path: "{{ terraform_dir }}/variables.tf"
|
||||||
|
regexp: '(variable "default_template_name"[^}]+default\s*=\s*)"[^"]+"'
|
||||||
|
replace: '\1"{{ new_template_name }}"'
|
||||||
|
when: template_name_changed
|
||||||
|
|
||||||
|
- name: Display update result
|
||||||
|
ansible.builtin.debug:
|
||||||
|
msg: "Updated terraform/variables.tf with new template name: {{ new_template_name }}"
|
||||||
|
when: template_name_changed
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ variable "default_target_node" {
|
|||||||
variable "default_template_name" {
|
variable "default_template_name" {
|
||||||
description = "Default template VM name to clone from"
|
description = "Default template VM name to clone from"
|
||||||
type = string
|
type = string
|
||||||
default = "nixos-25.11.20260131.41e216c"
|
default = "nixos-25.11.20260203.e576e3c"
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "default_ssh_public_key" {
|
variable "default_ssh_public_key" {
|
||||||
|
|||||||
Reference in New Issue
Block a user