Add username variable

This commit is contained in:
Doug Masiero 2025-05-23 20:26:17 -04:00
parent 47f8515e32
commit 6b228f63cf
9 changed files with 99 additions and 77 deletions

View File

@ -82,6 +82,11 @@ parameters:
type: String type: String
description: "OS variant for the VM" description: "OS variant for the VM"
default: "alpinelinux3.20" default: "alpinelinux3.20"
# User Configuration
username:
type: String
description: "Username to create during Alpine installation"
default: "moeny"
# Rarely Changed Network Configuration # Rarely Changed Network Configuration
dhcp: dhcp:
type: Boolean type: Boolean
@ -154,6 +159,7 @@ steps:
disk_path: "${disk_path}/${vm_name}.qcow2" disk_path: "${disk_path}/${vm_name}.qcow2"
staging_ip: $staging_ip staging_ip: $staging_ip
gateway_ip: $gateway_ip gateway_ip: $gateway_ip
username: $username
- name: install_packages - name: install_packages
description: Install Packages on the VM description: Install Packages on the VM
@ -178,12 +184,13 @@ steps:
install_docker_bool: $install_docker_bool install_docker_bool: $install_docker_bool
staging_ip: $staging_ip staging_ip: $staging_ip
- name: set_moeny_password - name: set_user_password
description: Set password for moeny user description: Set password for user
task: alpine::set_moeny_password task: alpine::set_user_password
targets: localhost targets: localhost
parameters: parameters:
staging_ip: $staging_ip staging_ip: $staging_ip
username: $username
- name: set_root_password - name: set_root_password
description: Set password for root user description: Set password for root user

View File

@ -6,6 +6,7 @@ VM_NAME="${PT_vm_name}"
DISK_PATH="${PT_disk_path}" DISK_PATH="${PT_disk_path}"
STAGING_IP="${PT_staging_ip}" STAGING_IP="${PT_staging_ip}"
GATEWAY_IP="${PT_gateway_ip}" GATEWAY_IP="${PT_gateway_ip}"
USERNAME="${PT_username:-moeny}"
# Wait for VM to be accessible via SSH # Wait for VM to be accessible via SSH
while ! ssh -o StrictHostKeyChecking=no -o ConnectTimeout=5 root@${STAGING_IP} "echo 'VM is accessible'"; do while ! ssh -o StrictHostKeyChecking=no -o ConnectTimeout=5 root@${STAGING_IP} "echo 'VM is accessible'"; do
@ -29,7 +30,7 @@ DNSOPTS=\"-n 8.8.8.8 8.8.4.4\"
TI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UbR+YqlmzmzGJXB6sWWTEnc9/GsVvLoculuzFYfa2qU9xFbuUTtqFRu6qor82TPAhy/yVWzIvRxlfuxKLpdU9paKiV+WtCkSpVoBgIH6soBE1swMX4ILIOGeFTrmCdBac4K1Bs0OarKtShR6PHdNiqPlwpCeQQDZD8ops69yBMc0t6poFZC9FYSj7arJEWvZN9YtUr+PJiYZQc+gIG4enPW1Zf4FEkXXvH/t6RaYMq9w/P5lIUNOVe169\" ROOTSSHKEY=\"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCRMJNdI/n/7xYN65zHFN8hlRSDg5OPJ12AwOsUyP8OmKCQTapoVQ/suvjaUTCtt8o28QNIQm1vAD03hFNzVJn6F6FJu9vUbR+YqlmzmzGJXB6sWWTEnc9/GsVvLoculuzFYfa2qU9xFbuUTtqFRu6qor82TPAhy/yVWzIvRxlfuxKLpdU9paKiV+WtCkSpVoBgIH6soBE1swMX4ILIOGeFTrmCdBac4K1Bs0OarKtShR6PHdNiqPlwpCeQQDZD8ops69yBMc0t6poFZC9FYSj7arJEWvZN9YtUr+PJiYZQc+gIG4enPW1Zf4FEkXXvH/t6RaYMq9w/P5lIUNOVe169\"
SSHDOPTS=\"-c openssh\" SSHDOPTS=\"-c openssh\"

View File

@ -1,23 +0,0 @@
#!/bin/bash
# Task to set password for moeny user (alpine::post_set_moeny_password)
# Function to check last command status
check_status() {
if [ $? -ne 0 ]; then
echo '{"status": "error", "message": "'"$1"'"}'
exit 1
fi
}
# Generate a random 15-character password locally
echo "Generating password..."
MOENY_PASSWORD=$(head -c 30 /dev/urandom | base64 | tr -dc 'a-zA-Z0-9' | head -c 15)
echo "Debug - Generated password: ${MOENY_PASSWORD}"
check_status "Failed to generate password"
# Set the password for moeny user
echo "moeny:${MOENY_PASSWORD}" | sudo chpasswd
check_status "Failed to set password for moeny user"
echo '{"status": "success", "message": "Moeny user password set to: '"${MOENY_PASSWORD}"'"}'
exit 0

View File

@ -0,0 +1,26 @@
#!/bin/bash
# Task to set password for user (alpine::post_set_user_password)
# Input Variables
USERNAME="${PT_username:-moeny}"
# Function to check last command status
check_status() {
if [ $? -ne 0 ]; then
echo '{"status": "error", "message": "'"$1"'"}'
exit 1
fi
}
# Generate a random 15-character password locally
echo "Generating password..."
USER_PASSWORD=$(head -c 30 /dev/urandom | base64 | tr -dc 'a-zA-Z0-9' | head -c 15)
echo "Debug - Generated password: ${USER_PASSWORD}"
check_status "Failed to generate password"
# Set the password for user
echo "${USERNAME}:${USER_PASSWORD}" | sudo chpasswd
check_status "Failed to set password for ${USERNAME} user"
echo "{\"status\": \"success\", \"message\": \"User ${USERNAME} password set to: ${USER_PASSWORD}\"}"
exit 0

View File

@ -1,26 +0,0 @@
#!/bin/bash
# Task to set password for moeny user (alpine::set_moeny_password)
# Input Variables
STAGING_IP="${PT_staging_ip}"
# Function to check last command status
check_status() {
if [ $? -ne 0 ]; then
echo '{"status": "error", "message": "'"$1"'"}'
exit 1
fi
}
# Generate a random 15-character password locally
echo "Generating password..."
MOENY_PASSWORD=$(head -c 30 /dev/urandom | base64 | tr -dc 'a-zA-Z0-9' | head -c 15)
echo "Debug - Generated password: ${MOENY_PASSWORD}"
check_status "Failed to generate password"
# Set the password for moeny user
ssh -o StrictHostKeyChecking=no root@${STAGING_IP} "echo 'moeny:${MOENY_PASSWORD}' | chpasswd"
check_status "Failed to set password for moeny user"
echo '{"status": "success", "message": "Moeny user password set to: '"${MOENY_PASSWORD}"'"}'
exit 0

View File

@ -0,0 +1,27 @@
#!/bin/bash
# Task to set password for user (alpine::set_user_password)
# Input Variables
STAGING_IP="${PT_staging_ip}"
USERNAME="${PT_username:-moeny}"
# Function to check last command status
check_status() {
if [ $? -ne 0 ]; then
echo '{"status": "error", "message": "'"$1"'"}'
exit 1
fi
}
# Generate a random 15-character password locally
echo "Generating password..."
USER_PASSWORD=$(head -c 30 /dev/urandom | base64 | tr -dc 'a-zA-Z0-9' | head -c 15)
echo "Debug - Generated password: ${USER_PASSWORD}"
check_status "Failed to generate password"
# Set the password for the user
ssh -o StrictHostKeyChecking=no root@${STAGING_IP} "echo '${USERNAME}:${USER_PASSWORD}' | chpasswd"
check_status "Failed to set password for ${USERNAME} user"
echo "{\"status\": \"success\", \"message\": \"User ${USERNAME} password set to: ${USER_PASSWORD}\"}"
exit 0

View File

@ -82,6 +82,11 @@ parameters:
type: String type: String
description: "OS variant for the VM" description: "OS variant for the VM"
default: "ubuntu22.04" default: "ubuntu22.04"
# User Configuration
username:
type: String
description: "Username to create during Ubuntu installation"
default: "moeny"
# Rarely Changed Network Configuration # Rarely Changed Network Configuration
dhcp: dhcp:
type: Boolean type: Boolean
@ -159,10 +164,12 @@ steps:
parameters: parameters:
install_docker_bool: $install_docker_bool install_docker_bool: $install_docker_bool
- name: set_moeny_password - name: set_user_password
description: Set password for moeny user description: Set password for user
task: ubuntu::set_moeny_password task: ubuntu::set_user_password
targets: $staging_ip targets: $staging_ip
parameters:
username: $username
- name: set_root_password - name: set_root_password
description: Set password for root user description: Set password for root user

View File

@ -1,21 +0,0 @@
#!/bin/bash
# Task to set password for moeny user (ubuntu::set_moeny_password)
# Function to check last command status
check_status() {
if [ $? -ne 0 ]; then
echo '{"status": "error", "message": "'"$1"'"}'
exit 1
fi
}
# Generate a random 15-character password (alphanumeric only)
MOENY_PASSWORD=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 15 | head -n 1)
check_status "Failed to generate password"
# Set the password for moeny user
echo "moeny:${MOENY_PASSWORD}" | sudo chpasswd
check_status "Failed to set password for moeny user"
echo '{"status": "success", "message": "Moeny user password set to: '"${MOENY_PASSWORD}"'"}'
exit 0

View File

@ -0,0 +1,24 @@
#!/bin/bash
# Task to set password for user (ubuntu::set_user_password)
# Input Variables
USERNAME="${PT_username:-moeny}"
# Function to check last command status
check_status() {
if [ $? -ne 0 ]; then
echo '{"status": "error", "message": "'"$1"'"}'
exit 1
fi
}
# Generate a random 15-character password (alphanumeric only)
USER_PASSWORD=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 15 | head -n 1)
check_status "Failed to generate password"
# Set the password for user
echo "${USERNAME}:${USER_PASSWORD}" | sudo chpasswd
check_status "Failed to set password for ${USERNAME} user"
echo "{\"status\": \"success\", \"message\": \"User ${USERNAME} password set to: ${USER_PASSWORD}\"}"
exit 0