使用Ansible克隆来自Bitbucket的git repo - 要求密码两到三次

tec*_*raf 5 git bitbucket ansible

我正在尝试使用Ansible 1.9.3(OSX)和https连接从Bitbucket克隆私有git存储库.我将密码存储在剪贴板中,并在被要求提供时使用粘贴.以下命令要求我提供两到三次密码(不定期,从不一次,不超过三次):

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

[~/devops]#
Run Code Online (Sandbox Code Playgroud)

在任何一次尝试中提供不正确的密码都会导致错误remote: Invalid username or password,因此输入错误是不可能的.-vvv选项没有提示.延迟输入密码似乎不会影响行为.

为什么我会问几次以及为什么次数不同?

nwi*_*ler 5

Ansible git模块不仅仅是克隆.它还可以更新现有的本地存储库,使用子模块等.(http://docs.ansible.com/ansible/git_module.html)

我的猜测是它正在进行多个操作,每个操作都需要访问远程BitBucket仓库.看一下git模块的源代码,即使只是clone步骤,它也会git使用不同的参数执行两次二进制文件.这可能发生在这里 - 取决于您是否已经克隆了repo,命令数量可能会有所不同,并且与本地repo交互的每个命令都会再次请求密码.

要解决此问题,您应该考虑在目标计算机上设置Git凭据帮助程序.在最简单的情况下,您可以使用cache实现,这将缓存您的密码几分钟.在这种情况下,输入一次就足够了.