简体   繁体   中英

Ansible playbook via jenkins user

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\\nubuntu@34.71.8.168: 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\\nubuntu@35.223.166.86: 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.

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 -- ubuntu@34.71.8.168 . 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM