你好,我有企业 git 服务器,我test-repo
在部署 ssh 密钥表单上创建了一个私有 ssh 密钥并添加了一个 ssh 密钥。我git
在常用角色中定义了一个角色,该角色具有以下 yml 定义。
---
- name: github enterprise private key
copy: >
src=id_rsa_ghe
dest=/etc/id_rsa_ghe
owner=root
group=root
mode=0600
- name: clone test-repo project
git:
repo: [email protected]:code/test-repo.git
dest: /etc/test-repo
accept_hostkey: true
key_file: /etc/id_rsa_ghe
在roles/common/git
我定义的files
文件夹中,我放置了用于 git clone 的私钥,但我仍然收到如下错误
致命:[localhost]:失败!=> {“changed”:false,“cmd”:[“/usr/bin/git”,“fetch”,“--tags”,“origin”],“failed”:true,“msg”:“无法下载远程对象和引用:错误:未找到存储库。\n致命:无法从远程存储库读取。\n\n请确保您具有正确的访问权限\n并且存储库存在。\n”}
以下是我的系统详细信息。我正在我的其中一台服务器上本地运行此剧本。
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 14.04.5 LTS
Release: 14.04
Codename: trusty
$ansible --version
ansible 2.2.1.0
config file = /etc/ansible/ansible.cfg
configured module search path = Default w/o overrides
以下是我收到的未找到存储库的实际错误。
使用模块文件 /usr/lib/python2.7/dist-packages/ansible/modules/core/source_control/git.py <127.0.0.1> 为用户建立本地连接:root <127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "
echo ~/.ansible/tmp/ansible-tmp-1487398723.48-100968102221507
" && echo ansible-tmp-1487398723.48-100968102221507="echo ~/.ansible/tmp/ansible-tmp-1487398723.48-100968102221507
" ) && sleep 0' <127.0.0.1> PUT /tmp/tmp2Bijvu TO /home/ubuntu/.ansible/tmp/ansible-tmp-1487398723.48-100968102221507/git.py <127.0.0.1> EXEC /bin/sh -c 'chmod u+x /home/ubuntu/.ansible/tmp/ansible-tmp-1487398723.48-100968102221507/ /home/ubuntu/.ansible/tmp/ansible-tmp-1487398723.48-100968102221507/git.py && sleep 0' <127.0.0.1> EXEC /bin/sh -c '/usr/bin/python /home/ubuntu/.ansible/tmp/ansible-tmp-1487398723.48-100968102221507/git.py; rm -rf "/home/ubuntu/.ansible/tmp/ansible-tmp-1487398723.48-100968102221507/"/dev/null 2>&1 && sleep 0' 致命:[localhost]:失败! => { “changed”:false, “cmd”:[ “/usr/bin/git”, “fetch”, “--tags”, “origin” ],“failed”:true, “invocation”:{ “module_args”:{ “accept_hostkey”:true, “bare”:false, “clone”:true, “depth”:null, “dest”:“/etc/dotfiles”, “executable”:null, “force”:false, “key_file”:“/etc/id_rsa_ghe”, “recursive”:true, “reference”:null, “refspec”:null, “remote”:“origin”, “repo”:“[电子邮件保护]:code/test-repo.git", "ssh_opts": null, "track_submodules": false, "umask": null, "update": true, "verify_commit": false, "version": "HEAD" }, "module_name": "git" }, "msg": "无法下载远程对象和引用:错误:未找到存储库。\nfatal:无法从远程存储库读取。\n\n请确保您具有正确的访问权限\n并且存储库存在。\n" }
答案1
看起来您的clone test-repo project
任务有语法错误,这就是 Ansible 找不到存储库的原因。将参数替换:
为/
,repo
如下所示:
- name: clone test-repo project
git:
repo: [email protected]/code/test-repo.git
dest: /etc/test-repo
accept_hostkey: true
key_file: /etc/id_rsa_ghe
您将使用它:
来定义非标准端口。