0
votes

I am trying to call my Ansible playbook from jenkins. But everytime i do so, i am getting permission denied for public key error. My objective is to push the playbook from local machine to GC VM.

Facts:

  1. Ansible and jenkins are installed on same machine
  2. My GC VM instance key is in /home/govind/Desktop/splukinstancekey.pem path. This is in my main user ("govind").
  3. In jenkins, i have generated a RSA key using ssh-keygen and added the same in user "govind" .ssh/authorized_keys. So i am able to make a connection from jenkins user to govind user (where ansible is installed ).

The problem is whenever i run the playbook from jenkins user , below error is thrown:

TASK [Gathering Facts] *********************************************************************************************************************** fatal: [34.71.8.168]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: Load key "/home/govind/Desktop/splunkinstancekey.pem": Permission denied\r\[email protected]: Permission denied (publickey).", "unreachable": true} fatal: [35.223.166.86]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: Load key "/home/govind/Desktop/splunkinstancekey.pem": Permission denied\r\[email protected]: Permission denied (publickey).", "unreachable": true}

From user "govind" i can easily ping remote servers via ansible command. Can anyone please help me in understanding what gap i might be missing from jenkins user. I understand that jenkins cannot access the pem file in as it does not belong to it. From various other posts i read that jenkins makes connection to user where ansible in installed and then that playbook is executed. But not able to make any progress.

1

1 Answers

0
votes

It seems like you should approach this from a ssh troubleshooting perspective. It sounds like you are trying to ssh from your jenkins box to the govind box. So, with the key pair you generated, you need to put the public key under authorized_keys on the govind box under the ubuntu user. ie- because in your error you are sshing as the ubuntu user -- [email protected]. You then should be able to ssh from the jenkins box to the govind box as the ubuntu user as you seem to be trying to do.