Guest User

Untitled

a guest
Apr 15th, 2025
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. configure_jl_user_and_password:
  2. stage: configure_jl_user_and_password
  3. script:
  4. - |
  5. mkdir -p ${automation_local_dir}
  6. cp -r ${automation_gitlab_dir}.my.cnf ${automation_local_dir}.my.cnf
  7. cp -r ${terraform_gitlab_dir} ${terraform_local_dir}
  8. cp -r ${ansible_gitlab_dir} ${ansible_local_dir}
  9.  
  10. all_host_ips="$(mysql --defaults-file=/tmp/automation-files/.my.cnf -e "USE customer_management; SELECT * FROM customer_${customer_name};" -s --skip-column-names | awk '{print $4}' | tail -n 3)"
  11. hosts_file="${automation_local_dir}ansible/hosts"
  12. rm -rf $hosts_file
  13.  
  14. cat > $hosts_file << EOF
  15. [remote_nodes]
  16. ${all_host_ips}
  17. [remote_nodes:vars]
  18. ansible_user=jl
  19. ansible_become_pass=Test1234!
  20. ansible_password=Test1234!
  21. ansible_ssh_pass=Test1234!
  22. ansible_sudo_password=Test1234!
  23. EOF
  24.  
  25. existing_password=$(mysql --defaults-file=/tmp/automation-files/.my.cnf -N -B -e "USE customer_management; SELECT CAST(AES_DECRYPT(password, '${decryption_key}') AS CHAR) AS decrypted_password FROM customer_access WHERE customer_name = '${customer_name}';" | tr -d '\n')
  26.  
  27. if [ -n "$existing_password" ]; then
  28. export static_password="$existing_password"
  29. echo "Using the existing password for customer '${customer_name}'"
  30. else
  31. static_password=$(openssl rand -base64 16)
  32. echo "Generated new password for customer '${customer_name}'"
  33. mysql --defaults-file=/tmp/automation-files/.my.cnf -e "USE customer_management; INSERT INTO customer_access (customer_name, customer_service, username, password) VALUES ('${customer_name}', '${customer_service}', '${static_username}', AES_ENCRYPT('${static_password}', '${encryption_key}'));"
  34. fi
  35.  
  36. cat > ${ansible_local_dir}playbook-folder/gen_password.vars << EOF
  37. static_username: "${static_username}"
  38. static_password: "${static_password}"
  39. EOF
  40.  
  41. ansible-playbook -i ${ansible_local_dir}hosts ${ansible_local_dir}playbook-folder/create_user2.yml -vvvv
  42.  
  43. rm -rf ${automation_local_dir}
Add Comment
Please, Sign In to add comment