Not able to connect remote host via jenkins to run ansible playbook

0 votes

Not able to connect remote host via jenkins to run ansible playbook.I am able to run the playbook directly via the terminal but getting error when i do with jenkins getting below error.

fatal: [webservers]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: ubuntu@<<ipaddress-masked>>: Permission denied (publickey).", "unreachable": true}
	to retry, use: --limit @/etc/ansible/ansiblecopy.retry

I have masked the ipaddress
Jenkins and ansible server are on same machine
Apr 2 in Jenkins by Nishant
• 160 points

recategorized Apr 2 by Nishant 155 views

Hey @Nishant, Can you post the output of the following command

ansible all -m ping -vvv

From the terminal when i excute ansible all -m ping -vvv - below is the output

webservers | SUCCESS => {
    "changed": false,
    "invocation": {
        "module_args": {
            "data": "pong"
        }
    },
    "ping": "pong"
}

When i execute from Jenkins under Build and use execute shell then also i get the success

webservers | SUCCESS => {
    "changed": false,
    "invocation": {
        "module_args": {
            "data": "pong"
        }
    },
    "ping": "pong"
}
META: ran handlers
META: ran handlers
Finished: SUCCESS

However when i execute from Anbile playbook(added ansible plugin) using plugin

TASK [Gathering Facts] *********************************************************
fatal: [webservers]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: ubuntu@17x.xx.xx.xx: Permission denied (publickey).", "unreachable": true}
to retry, use: --limit @/etc/ansible/first.retry
PLAY RECAP *********************************************************************
webservers                 : ok=0    changed=0    unreachable=1    failed=0  

This will be related to some permissions issues within jenkins and i have ansible server and jenkins server on the same machine

Use SSH keys and add the Jenkins user's Private key to the Jenkins credentials store and select those in the Ansible Configuration.

Make sure you've done this!

Thanks a lot this helps can you please let me know why Jenkins credentials need to be stored and used in ansible Config i used ubuntu credentials and was trying to use those in ansible config, if you can throw some light or any link will help

That's how you let Ansible know that its a Jenkins build. This lets you ssh into the remote hosts as Jenkins and ansible have been configured with the required keys and credentials.

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Jenkins

0 votes
1 answer

Error while talking to remote Oracle DB using Jenkins-CI

I installed Oracle XE to talk to ...READ MORE

answered May 1, 2018 in Jenkins by shubham
• 6,500 points
171 views
+2 votes
6 answers
0 votes
1 answer

Error Jenkins: Failed to connect to repository

This happens when you create the ssh ...READ MORE

answered Jul 6, 2018 in Jenkins by Sophie may
• 9,050 points
293 views
0 votes
1 answer

How do I pass value from my Fake # script to the host build server (Jenkins)

You can use the EnvInject plugin to pass environment ...READ MORE

answered Jul 11, 2018 in Jenkins by Kalgi
• 2,620 points
41 views
0 votes
5 answers

How to resolve this error “Jenkins Host key verification failed”?

HI Mam, Please check the following solution:: 1. Switch ...READ MORE

answered May 3 in Jenkins by anonymous
2,092 views
0 votes
1 answer
0 votes
1 answer

permissions related to AWS ECR

if you add allowContainerRegistry: true, kops will add those permissions ...READ MORE

answered Oct 9, 2018 in Kubernetes by Kalgi
• 35,800 points
30 views
+13 votes
2 answers

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.