Reputation: 17
How to inject passwords to the build as environment variables(these are job passwords) for deployment through ansible via pipeline or dsl script
Upvotes: 0
Views: 2534
Reputation: 1323973
First, those job passwords should be registered as credentials inside Jenkins.
Second, you can use said file when calling your ansible-playbook
command, through the Credentials Binding plugin.
See "How to use multiple credentials in withCredentials in Jenkins Pipeline"
node {
withCredentials([
usernamePassword(credentialsId: credsId1, usernameVariable: 'USER1', passwordVariable: 'PASS1'),
usernamePassword(credentialsId: credsId2, usernameVariable: 'USER2', passwordVariable: 'PASS2')
...
]) {
sh '''
set +x
ansible-playbook /path/to/ansible-playbook.yml -i /path/to/hosts_list -u AUTO_USER --private-key=/path/to/private-key \
-e $USER1=$PASS1 -e $USER2=$PASS2
'''
}
}
Note: the file should have a JSON content, with your
Upvotes: 1