bolt/vm_automation/ubuntu/tasks/set_moeny_password.sh

21 lines
668 B
Bash
Executable File

#!/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