Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- configure_jl_user_and_password:
- stage: configure_jl_user_and_password
- script:
- - |
- mkdir -p ${automation_local_dir}
- cp -r ${automation_gitlab_dir}.my.cnf ${automation_local_dir}.my.cnf
- cp -r ${terraform_gitlab_dir} ${terraform_local_dir}
- cp -r ${ansible_gitlab_dir} ${ansible_local_dir}
- 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)"
- hosts_file="${automation_local_dir}ansible/hosts"
- rm -rf $hosts_file
- cat > $hosts_file << EOF
- [remote_nodes]
- ${all_host_ips}
- [remote_nodes:vars]
- ansible_user=jl
- ansible_become_pass=Test1234!
- ansible_password=Test1234!
- ansible_ssh_pass=Test1234!
- ansible_sudo_password=Test1234!
- EOF
- 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')
- if [ -n "$existing_password" ]; then
- export static_password="$existing_password"
- echo "Using the existing password for customer '${customer_name}'"
- else
- static_password=$(openssl rand -base64 16)
- echo "Generated new password for customer '${customer_name}'"
- 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}'));"
- fi
- cat > ${ansible_local_dir}playbook-folder/gen_password.vars << EOF
- static_username: "${static_username}"
- static_password: "${static_password}"
- EOF
- ansible-playbook -i ${ansible_local_dir}hosts ${ansible_local_dir}playbook-folder/create_user2.yml -vvvv
- rm -rf ${automation_local_dir}
Add Comment
Please, Sign In to add comment