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?
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With