Changes to reference template hostname until the vm is renamed

This commit is contained in:
2026-02-02 16:39:27 -05:00
parent 678625e634
commit 5426456a4d
4 changed files with 77 additions and 3 deletions

51
Jenkinsfile vendored
View File

@@ -42,6 +42,8 @@ pipeline {
environment {
ANSIBLE_HOST_KEY_CHECKING = 'False'
ANSIBLE_FORCE_COLOR = 'true'
VM_TEMPLATE_HOSTNAME = 'ubuntu24vm'
LXC_TEMPLATE_HOSTNAME = 'ubuntu24lxc'
}
stages {
@@ -97,8 +99,10 @@ pipeline {
stage('Wait for Machine to Boot') {
steps {
script {
def targetHost = "${params.HOSTNAME}.lan"
echo "Waiting for ${targetHost} to become available..."
// Use template hostname for ping since the cloned machine still has the template's hostname
def templateHost = params.PROVISION_TYPE == 'VM' ? env.VM_TEMPLATE_HOSTNAME : env.LXC_TEMPLATE_HOSTNAME
def targetHost = "${templateHost}.lan"
echo "Waiting for ${targetHost} (template hostname) to become available..."
// Wait up to 3 minutes for the machine to respond to ping
timeout(time: 3, unit: 'MINUTES') {
@@ -120,7 +124,8 @@ pipeline {
stage('Copy Jenkins SSH Key') {
steps {
script {
def targetHost = "${params.HOSTNAME}.lan"
def templateHost = params.PROVISION_TYPE == 'VM' ? env.VM_TEMPLATE_HOSTNAME : env.LXC_TEMPLATE_HOSTNAME
def targetHost = "${templateHost}.lan"
// Use sshpass or expect to handle the initial connection
// This assumes the template has a default user that accepts the key
@@ -131,6 +136,46 @@ pipeline {
}
}
stage('Set Hostname') {
steps {
script {
def templateHost = params.PROVISION_TYPE == 'VM' ? env.VM_TEMPLATE_HOSTNAME : env.LXC_TEMPLATE_HOSTNAME
def currentHost = "${templateHost}.lan"
def newHostname = params.HOSTNAME
// Create a temporary inventory file with the current host
writeFile file: 'temp_inventory.yml', text: """---
all:
hosts:
new_host:
ansible_host: ${currentHost}
ansible_user: jenkins
ansible_ssh_private_key_file: /var/lib/jenkins/.ssh/id_ed25519
"""
sh """
ansible-playbook playbooks/set_hostname.yml \
-i temp_inventory.yml \
-e "new_hostname=${newHostname}"
"""
// Wait for the machine to come back up with the new hostname
echo "Waiting for ${newHostname}.lan to become available..."
sleep(time: 30, unit: 'SECONDS')
timeout(time: 3, unit: 'MINUTES') {
waitUntil {
def result = sh(
script: "ping -c 1 ${newHostname}.lan > /dev/null 2>&1",
returnStatus: true
)
return result == 0
}
}
}
}
}
stage('Configure Machine') {
steps {
script {