From abdd594f60efa8b26b09c5fa07c9ddc0d5d8a54c Mon Sep 17 00:00:00 2001 From: mpavlov Date: Thu, 26 Sep 2024 21:18:07 +0300 Subject: [PATCH] changed user to deployer --- Jenkinsfile | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 70c19d7..d13aee9 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -2,8 +2,6 @@ pipeline { agent any parameters { string(name: "target_host", defaultValue: "", trim: true, description: "Target host") - string(name: "username", defaultValue: "", trim: true, description: "Ansible user") - password(name: "password", defaultValue: "", description: "Ansible password") booleanParam(name: "rproxy_install", defaultValue: true, description: "Install Rproxy") base64File(name: "rootca", description: "RootCA (only for 'Install Rproxy')") base64File(name: "rootca_key", description: "RootCA key (only for 'Install Rproxy')") @@ -37,8 +35,13 @@ pipeline { } steps { script { - wrap([$class: 'MaskPasswordsBuildWrapper', varPasswordPairs: [[password: params.password]]]) { - sh 'ansible-playbook rproxy.yml -i ${target_host}, -t install -u ${username} -e "ansible_password=${password} rproxy_service_name=${rproxy_service_name} rproxy_service_port=${rproxy_service_port} rproxy_service_address=${rproxy_service_address}"' + withCredentials([ + sshUserPrivateKey(credentialsId: 'JENKINS_DEPLOYER_KEY', keyFileVariable: 'SSH_KEY'), + usernamePassword(credentialsId:'JENKINS_DEPLOYER_PASS', usernameVariable: 'username', passwordVariable: 'password') + ]) { + wrap([$class: 'MaskPasswordsBuildWrapper', varPasswordPairs: [[password: env.password]]]) { + sh 'ansible-playbook rproxy.yml -i ${target_host}, -t install --private-key ${SSH_KEY} -u ${username} -e "ansible_password=${password} rproxy_service_name=${rproxy_service_name} rproxy_service_port=${rproxy_service_port} rproxy_service_address=${rproxy_service_address}"' + } } } } @@ -51,8 +54,13 @@ pipeline { } steps { script { - wrap([$class: 'MaskPasswordsBuildWrapper', varPasswordPairs: [[password: params.password]]]) { - sh 'ansible-playbook rproxy.yml -i ${target_host}, -t add_config -u ${username} -e "ansible_password=${password} rproxy_service_name=${rproxy_service_name} rproxy_service_port=${rproxy_service_port} rproxy_service_address=${rproxy_service_address}"' + withCredentials([ + sshUserPrivateKey(credentialsId: 'JENKINS_DEPLOYER_KEY', keyFileVariable: 'SSH_KEY'), + usernamePassword(credentialsId:'JENKINS_DEPLOYER_PASS', usernameVariable: 'username', passwordVariable: 'password') + ]) { + wrap([$class: 'MaskPasswordsBuildWrapper', varPasswordPairs: [[password: env.password]]]) { + sh 'ansible-playbook rproxy.yml -i ${target_host}, -t add_config --private-key ${SSH_KEY} -u ${username} -e "ansible_password=${password} rproxy_service_name=${rproxy_service_name} rproxy_service_port=${rproxy_service_port} rproxy_service_address=${rproxy_service_address}"' + } } } }