我在使用 Ansible 时遇到了一个令人不安的问题。我使用当前主机的 ssh 密钥在我的环境中设置 git 克隆:
- name: Add user Public Key
copy:
src: "/Users/alexgrs/.ssh/id_rsa.pub"
dest: "/home/vagrant/.ssh/id_rsa.pub"
mode: 0644
- name: Add user Private Key
copy:
src: "/Users/alexgrs/.ssh/id_rsa"
dest: "/home/vagrant/.ssh/id_rsa"
mode: 0600
- name: Clone Repository
git:
repo: repo.git
dest: /home/vagrant/workspace/
update: true
accept_hostkey: true
key_file: "/home/vagrant/.ssh/id_rsa.pub"
If I vagrant ssh
在 Vagrant 上并执行git pull repo
有用。但是当我做一个vagrant provision
我收到以下错误消息:
stderr: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository exists.
我很确定我的公钥没有被流浪者条款使用,但我无法检测到原因。
您已经看到过此类问题吗?
谢谢。
EDIT:看起来 ansible 并没有进行 git 克隆,而是尝试以下命令:
/usr/bin/git ls-remote ssh://repo.git -h refs/heads/HEAD
我在我的流浪盒中尝试过,并且遇到了相同的权限被拒绝的问题。
恕我直言,复制私钥从来都不是一个好主意。更好的选择是启用ssh代理转发 http://www.unixwiz.net/techtips/ssh-agent-forwarding.html.
您可以在本地进行全局操作.ssh/config
:
ForwardAgent yes
或者在你的ansible.cfg
:
[ssh_connection]
ssh_args= -A
无论如何,您需要确保主机/虚拟机接受代理转发。在远程/etc/ssh/sshd_config
必须定义这一点:
AllowAgentForwarding yes
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)