Git pull from bitbucket using ansible and jenkins

ansible-playbookbitbucketgit

Hi everyone I am new on ansible, I am working on Ubuntu 16.04 and ansible 2.2, how to pull bitbucket repository to remote server using ansible? I have connected to the hosts and able to ping or running simple command using my ansible to the remote server, I have tried this method cloning private repo on remote server but I got this error:

"stderr": "Cloning into '/home/deploy/test'…\nPermission denied (publickey).\r\nfatal: Could not read from remote repository.\n\nPlease make sure you have the correct access rights\nand the repository exists.\n",

Do I need to generate ssh key from bitbucket or inserting my public key to bitbucket? Like I said before I am very new and this is quite urgent, thank you.

Best Answer

The best solution is to generate a key pair in your workstation, upload the public key to bitbucket, and copy the private key to the user with which you do the git clone in the destination server. With that solution, you can automate deploy to multiple servers without generating a new key pair in each one.

You can specify the key file with the option key_file from Ansible git module