Add username variable
This commit is contained in:
parent
47f8515e32
commit
ff7d3fe968
@ -82,6 +82,11 @@ parameters:
|
||||
type: String
|
||||
description: "OS variant for the VM"
|
||||
default: "alpinelinux3.20"
|
||||
# User Configuration
|
||||
username:
|
||||
type: String
|
||||
description: "Username to create during Alpine installation"
|
||||
default: "moeny"
|
||||
# Rarely Changed Network Configuration
|
||||
dhcp:
|
||||
type: Boolean
|
||||
@ -154,6 +159,7 @@ steps:
|
||||
disk_path: "${disk_path}/${vm_name}.qcow2"
|
||||
staging_ip: $staging_ip
|
||||
gateway_ip: $gateway_ip
|
||||
username: $username
|
||||
|
||||
- name: install_packages
|
||||
description: Install Packages on the VM
|
||||
@ -161,6 +167,7 @@ steps:
|
||||
targets: localhost
|
||||
parameters:
|
||||
staging_ip: $staging_ip
|
||||
username: $username
|
||||
|
||||
- name: install_zabbix
|
||||
description: Install Zabbix on the VM
|
||||
@ -178,12 +185,13 @@ steps:
|
||||
install_docker_bool: $install_docker_bool
|
||||
staging_ip: $staging_ip
|
||||
|
||||
- name: set_moeny_password
|
||||
description: Set password for moeny user
|
||||
task: alpine::set_moeny_password
|
||||
- name: set_user_password
|
||||
description: Set password for user
|
||||
task: alpine::set_user_password
|
||||
targets: localhost
|
||||
parameters:
|
||||
staging_ip: $staging_ip
|
||||
username: $username
|
||||
|
||||
- name: set_root_password
|
||||
description: Set password for root user
|
||||
|
@ -6,6 +6,7 @@ VM_NAME="${PT_vm_name}"
|
||||
DISK_PATH="${PT_disk_path}"
|
||||
STAGING_IP="${PT_staging_ip}"
|
||||
GATEWAY_IP="${PT_gateway_ip}"
|
||||
USERNAME="${PT_username:-moeny}"
|
||||
|
||||
# Wait for VM to be accessible via SSH
|
||||
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\"
|
||||
TIMEZONEOPTS=\"-z UTC\"
|
||||
PROXYOPTS=\"none\"
|
||||
APKREPOSOPTS=\"-1\"
|
||||
USEROPTS=\"-a -u moeny\"
|
||||
USEROPTS=\"-a -u ${USERNAME}\"
|
||||
USERSSHKEY=\"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCRMJNdI/n/7xYN65zHFN8hlRSDg5OPJ12AwOsUyP8OmKCQTapoVQ/suvjaUTCtt8o28QNIQm1vAD03hFNzVJn6F6FJu9vUbR+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\"
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
# Input Variables
|
||||
STAGING_IP="${PT_staging_ip}"
|
||||
USERNAME="${PT_username:-moeny}"
|
||||
|
||||
# Uncomment to enable community repository
|
||||
ssh -o StrictHostKeyChecking=no root@${STAGING_IP} "sed -i '3s/^#//' /etc/apk/repositories"
|
||||
@ -11,13 +12,13 @@ ssh -o StrictHostKeyChecking=no root@${STAGING_IP} "sed -i '3s/^#//' /etc/apk/re
|
||||
ssh -o StrictHostKeyChecking=no root@${STAGING_IP} "apk update && apk add --no-cache vim curl git fping htop sudo bash mtr rsync tmux"
|
||||
|
||||
# Change default shell to bash
|
||||
ssh -o StrictHostKeyChecking=no root@${STAGING_IP} "sed -i -E '/^(root|moeny):/ s:/bin/sh$:/bin/bash:' /etc/passwd"
|
||||
ssh -o StrictHostKeyChecking=no root@${STAGING_IP} "sed -i -E '/^(root|'${USERNAME}'):/ s:/bin/sh$:/bin/bash:' /etc/passwd"
|
||||
|
||||
# Set mouse for vim
|
||||
ssh -o StrictHostKeyChecking=no root@${STAGING_IP} "sed -i '1i let skip_defaults_vim = 1\nset mouse=' /etc/vim/vimrc"
|
||||
|
||||
# Add moeny user to sudo group
|
||||
ssh -o StrictHostKeyChecking=no root@${STAGING_IP} "addgroup sudo;addgroup moeny sudo"
|
||||
# Add user to sudo group
|
||||
ssh -o StrictHostKeyChecking=no root@${STAGING_IP} "addgroup sudo;addgroup '${USERNAME}' sudo"
|
||||
|
||||
# Set no password to sudo group
|
||||
ssh -o StrictHostKeyChecking=no root@${STAGING_IP} "echo '%sudo ALL=(ALL) NOPASSWD: ALL' | tee -a /etc/sudoers.d/nopasswd_sudo_group"
|
||||
|
@ -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
|
26
vm_automation/alpine/tasks/post_set_user_password.sh
Normal file
26
vm_automation/alpine/tasks/post_set_user_password.sh
Normal 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
|
@ -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
|
27
vm_automation/alpine/tasks/set_user_password.sh
Normal file
27
vm_automation/alpine/tasks/set_user_password.sh
Normal 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
|
@ -82,6 +82,11 @@ parameters:
|
||||
type: String
|
||||
description: "OS variant for the VM"
|
||||
default: "ubuntu22.04"
|
||||
# User Configuration
|
||||
username:
|
||||
type: String
|
||||
description: "Username to create during Ubuntu installation"
|
||||
default: "moeny"
|
||||
# Rarely Changed Network Configuration
|
||||
dhcp:
|
||||
type: Boolean
|
||||
@ -159,10 +164,12 @@ steps:
|
||||
parameters:
|
||||
install_docker_bool: $install_docker_bool
|
||||
|
||||
- name: set_moeny_password
|
||||
description: Set password for moeny user
|
||||
task: ubuntu::set_moeny_password
|
||||
- name: set_user_password
|
||||
description: Set password for user
|
||||
task: ubuntu::set_user_password
|
||||
targets: $staging_ip
|
||||
parameters:
|
||||
username: $username
|
||||
|
||||
- name: set_root_password
|
||||
description: Set password for root user
|
||||
|
@ -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
|
24
vm_automation/ubuntu/tasks/set_user_password.sh
Executable file
24
vm_automation/ubuntu/tasks/set_user_password.sh
Executable 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
|
Loading…
Reference in New Issue
Block a user