1

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.

1

2 Answers 2

2

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

1
  • thanks tried this method and it works, the next challenge is to change the content, this is a laravel project and the .env not copied by the way, that's the next challenge :D
    – spacetrack
    Aug 28, 2017 at 8:08
0

in general using private key is not considered safe because if the target server is hacked this key is exposed. The secure alternative is using ssh agent forwarding from the ansible instance. this way only the ansible key needs to be registered with bitbucket and it is never exposed on the target hosts. take a look at this article: https://www.jeffgeerling.com/blog/2018/cloning-private-github-repositories-ansible-on-remote-server-through-ssh if you want to know how to add ssh key to the ssh-agent: https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .