techraf
techraf

Reputation: 68559

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?

Upvotes: 5

Views: 4763

Answers (1)

nwinkler
nwinkler

Reputation: 54467

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.

Upvotes: 5

Related Questions