Hello Ia trying to run an ansible playbook from in a declarative pipeline and passing a user credential via a credential parameter.
When the jobs run I select a private credential and use it in the ansible-playbook step.
However the job fails, since it cannot connect to the target hots.
From looking in the logs it appears to be the problem, that the credential i pass is not used.
In the logs on can sees that the connection is tried as user none and the keys from the jenkins user homedirectory are tried.
However I would have expected the the username and the private key from the credential are used.
Is there a way to achieve this?
Here are the relevant code snippets from the pipeline
parameters {
credentials credentialType: 'com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey',
name: 'DEPLOY_CRED', required: true, defaultValue: '',
description: 'The credential used on the target systems for the deployment (Username, SSH Key)'
}
I don’t know anything about this plugin specifically, but I wonder if its not supporting user credentials or something.
I recommend trying something simplier to debug with
steps {
script { // I don't know if you need a script tag for this.
sshagent (credentials: [env.DEPLOY_CRED]) {
sh 'ssh -v -o StrictHostKeyChecking=no whateverhostname uname -a'
}
}
}
which would give a bunch of debugging, and use the ssh agent plugin which I know works.
In fact the support for the credentialId parameter was my main reason to use the ansible plugin instead of running the playbook via a sh step. It was my hope that this would simply the boilerplate code for passing the credentials from the credential parameter to the playbook.
for debugging I used the extra parameter to pass the -vvvv option to ansible-playbook and the playbook provided quit a lot debug output, especially concerning the connection establishment.
From what I saw in the log, is, that the credential parameter selected my credential containing my userid and my private key,
However from the log for establishing the SSL connection it seams it ignores these credentials.
The user is reported as none and as keys the keys form the jenkins User directory are used.