Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cloning a git repo from Bitbucket with Ansible - asked for password two or three times

I am trying to clone a private git repository from Bitbucket using Ansible 1.9.3 (OSX) and an https connection. I have my password stored in the clipboard and use pasting when asked to provide it. The following command requires me to provide the password two or three times (irregularly, never once and never more than three):

[~/devops]# ansible localhost -c local -m git -a "repo=https://[email protected]/techraf/ansible-local.git dest=~/devops/ansible-local"
Password for 'https://[email protected]':
Password for 'https://[email protected]':
Password for 'https://[email protected]':
localhost | success >> {
    "after": "445dfaf39a6245bc30149dd722b1a17d0e56ba55",
    "before": null,
    "changed": true
}

[~/devops]#

Providing incorrect password on either try immediately results in an error remote: Invalid username or password, so typing mistake is out of question. -vvv option gives no hint. Delaying entering the password does not seem to influence the behaviour.

Why am I asked several times and why the number of times differ?

like image 214
techraf Avatar asked Sep 07 '15 11:09

techraf


People also ask

How many times do you need to clone a Git repository?

Purpose: repo-to-repo collaboration development copy Like git init , cloning is generally a one-time operation. Once a developer has obtained a working copy, all version control operations and collaborations are managed through their local repository.

How do I clone a Git repository in Ansible?

Cloning a Git Repository with Ansible playbook In the playbook above, you started by defining a new task and gave it the name “Clone a GitHub repository". Next, you are using the git module to specify the link to the SQLite GitHub repository. You then proceed to define the destination for the cloned repository.

Does Git clone require password?

If Git prompts you for a username and password every time you try to interact with GitHub, you're probably using the HTTPS clone URL for your repository. Using an HTTPS remote URL has some advantages compared with using SSH. It's easier to set up than SSH, and usually works through strict firewalls and proxies.

How do I clone a Bitbucket repository without username and password?

The only way you can clone a repository without having to enter your password would be to make the repository public, then a password is not required. But note that you would not be able to push anything back to Bitbucket without entering a password/using SSH.


1 Answers

The Ansible git module does more than just cloning. It can also update an existing local repository, work with submodules, etc. (http://docs.ansible.com/ansible/git_module.html)

My guess is that it's doing multiple operations, where each one requires access to the remote BitBucket repo. A look at the git module's source code shows that even for just the clone step, it's executing the git binary a couple of times with different parameters. It's possible that this is happening here - depending on whether you have the repo already cloned, the number of commands may vary, and each command that interacts with your local repo will ask for the password again.

To work around this, you should consider setting up a Git credential helper on the target machine. In the easiest case, you can use the cache implementation, which will cache your password for a couple of minutes. Entering it once should be sufficient in this case.

like image 132
nwinkler Avatar answered Sep 30 '22 07:09

nwinkler