From 887536ced7fe30a4c637615a85115ad89593ca8d Mon Sep 17 00:00:00 2001 From: moeny-matt Date: Thu, 24 Apr 2025 19:20:59 -0400 Subject: [PATCH] Script to set moeny user password --- .gitignore | 1 + vm_automation/alpine/plans/create_vm.yaml | 7 +++++ .../alpine/tasks/set_moeny_password.sh | 26 +++++++++++++++++++ vm_automation/ubuntu/plans/create_vm.yaml | 5 ++++ vm_automation/ubuntu/tasks/create_vm.sh | 2 +- .../ubuntu/tasks/set_moeny_password.sh | 21 +++++++++++++++ 6 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 vm_automation/alpine/tasks/set_moeny_password.sh create mode 100755 vm_automation/ubuntu/tasks/set_moeny_password.sh diff --git a/.gitignore b/.gitignore index 16d0241..ecc0610 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ bolt-debug.log .plugin_cache.json .task_cache.json .rerun.json +keys \ No newline at end of file diff --git a/vm_automation/alpine/plans/create_vm.yaml b/vm_automation/alpine/plans/create_vm.yaml index 5994af7..e9c8e65 100644 --- a/vm_automation/alpine/plans/create_vm.yaml +++ b/vm_automation/alpine/plans/create_vm.yaml @@ -154,6 +154,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 + targets: localhost + parameters: + staging_ip: $staging_ip + - name: system_setup task: alpine::system_setup targets: localhost diff --git a/vm_automation/alpine/tasks/set_moeny_password.sh b/vm_automation/alpine/tasks/set_moeny_password.sh new file mode 100644 index 0000000..5e70c78 --- /dev/null +++ b/vm_automation/alpine/tasks/set_moeny_password.sh @@ -0,0 +1,26 @@ +#!/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 \ No newline at end of file diff --git a/vm_automation/ubuntu/plans/create_vm.yaml b/vm_automation/ubuntu/plans/create_vm.yaml index bb672c5..71c8996 100644 --- a/vm_automation/ubuntu/plans/create_vm.yaml +++ b/vm_automation/ubuntu/plans/create_vm.yaml @@ -135,6 +135,11 @@ steps: parameters: install_docker_bool: $install_docker_bool + - name: set_moeny_password + description: Set password for moeny user + task: ubuntu::set_moeny_password + targets: $staging_ip + - name: system_setup task: ubuntu::system_setup targets: $staging_ip diff --git a/vm_automation/ubuntu/tasks/create_vm.sh b/vm_automation/ubuntu/tasks/create_vm.sh index 5fb6f42..a903b40 100755 --- a/vm_automation/ubuntu/tasks/create_vm.sh +++ b/vm_automation/ubuntu/tasks/create_vm.sh @@ -30,4 +30,4 @@ virt-install \ --autostart \ --wait -1 -sleep 45 \ No newline at end of file +sleep 90 \ No newline at end of file diff --git a/vm_automation/ubuntu/tasks/set_moeny_password.sh b/vm_automation/ubuntu/tasks/set_moeny_password.sh new file mode 100755 index 0000000..daf54b4 --- /dev/null +++ b/vm_automation/ubuntu/tasks/set_moeny_password.sh @@ -0,0 +1,21 @@ +#!/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 \ No newline at end of file