title: Executing Ansible Playbook using Jenkins
body: <p>I know there's a related question here: <a href="https://stackoverflow.com/questions/41771060/invoke-ansible-playbook-in-jenkins?rq=1">Invoke Ansible playbook in Jenkins</a></p>
  
  <p>But this question is different from that in some perspectives:</p>
  
  <p>So I have Jenkins and Ansible installed in a single server (EC2 instance). I have created a playbook.yml which copies files from this server to another server. This is successful if I do ansible-playbook playbook.yml using ec2-user.</p>
  
  <p>The same if I try to do using Jenkins (Created a project and added a build step as run ansible playbook and mentioned the location of playbook.yml and running as sudo ec2-user). This is failing with the error:</p>
  
  <pre><code>fatal: [172.xx.xx.xx]: UNREACHABLE! =&gt; {"changed": false, "msg": "Failed to connect to the host via ssh: no such identity: /home/ec2-user/.ssh/Host_Keypair.pem: Permission denied\r\nPermission denied (publickey).\r\n", "unreachable": true}
  to retry, use: --limit @/var/lib/jenkins/workspace/Ansible/copy.retr
  </code></pre>
  
  <p>playbook.yml:</p>
  
  <pre><code>---
  - hosts: 172.xx.xx.xx
    remote_user: ec2-user
    become: yes
    become_method: sudo
    tasks:
     - copy:
       src: /var/lib/jenkins/workspace/Ansible/myfile.conf
       dest: /etc/myfile.conf
       owner: ec2-user
       group: ec2-user
       mode: 0644
  </code></pre>
  
  <p>I am stuck on this and not able to move to next step without executing this. Can anyone please help me on what other configuration I am missing (possibly in Jenkins side). Any help would be much appreciated.</p>