We developed declarative pipeline code to execute an Ansible playbook. We tested the playbook from CLI and it is working properly. My playbook actually performs some shell commands on remote server.
SSH configuration between two servers has been done: I have generated an ssh key and copied it to the remote server, and I am able to ping the server.
The Error msg:
ansible-playbook /var/lib/jenkins/workspace/test1/playbook2.yml -i
/var/lib/jenkins/workspace/test1/inventory.ini -b --become-user root
[WARNING] Ansible is in a world writable directory
(/var/lib/jenkins/workspace/test1), ignoring it as an ansible.cfg source
fatal: [17.14.69.21]: UNREACHABLE! => {"changed": false, "msg": "Failed to
connect to the host via ssh: Permission denied (publickey,gssapi-
keyex,gssapi-with-mic,password).\r\n", "unreachable": true}
[17.14.69.21]:
FATAL: command execution failed
hudson.AbortException: Ansible playbook execution failed.
I have given sudo access to Jenkins user and Jenkins is running as Jenkins user.
ansible-playbook -vvv