Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ansible:从私有git repo使用pip安装软件包_Git_Ssh_Pip_Ansible - Fatal编程技术网

Ansible:从私有git repo使用pip安装软件包

Ansible:从私有git repo使用pip安装软件包,git,ssh,pip,ansible,Git,Ssh,Pip,Ansible,我正在尝试使用ansible的pip模块从私有git repo安装一个包,方法如下: - name: Install my package pip: name='git+ssh://git@github.com/mycompany/my-repo.git#egg=0.1.0' virtualenv=/path/to/venv 但是,当我尝试使用vagrant提供此功能时,这会挂起,很可能是因为它会提示确认将密钥添加到已知主机列表中。事实上,当我在《流浪汉》杂志上发表这篇文章时

我正在尝试使用ansible的pip模块从私有git repo安装一个包,方法如下:

- name: Install my package
  pip: name='git+ssh://git@github.com/mycompany/my-repo.git#egg=0.1.0'
       virtualenv=/path/to/venv
但是,当我尝试使用vagrant提供此功能时,这会挂起,很可能是因为它会提示确认将密钥添加到已知主机列表中。事实上,当我在《流浪汉》杂志上发表这篇文章时:

pip install git+ssh://git@github.com/mycompany/my-repo.git#egg=0.1.0
它会提示确认将github添加到已知主机,然后工作正常

如果我用
accept\u hostkey=yes
克隆它:

- name: Clone repo
  git: repo=git@github.com:mycompany/my-repo.git
       dest=/path/to/dest
       accept_hostkey=yes
       recursive=no
它工作正常,因为它接受在vagrant上复制的主机密钥。对于pip模块,没有这样的选项,有没有办法解决这个问题?
作为替代方案,我可以先进行克隆,然后进行
python setup.py安装
,但我更愿意通过pip一步完成。

如果这个问题是关于授权主机密钥,而不是关于是否有正确的私钥,那么您可以执行以下操作

在运行
pip
之前,您始终可以在“~/.ssh/authorized_keys”中手动授权主机密钥

例如:


要获得访问专用Github存储库的正确私钥,您可以使用SSH代理转发。

运行此任务以将主机密钥添加到您的
已知\u主机文件中:

- name: Whitelist github.com
  shell: if [ ! -n "$(grep "^github.com " ~/.ssh/known_hosts)" ]; then ssh-keyscan github.com >> ~/.ssh/known_hosts 2>/dev/null; fi

checkout
命令挂起,因为
github.com
不在Ansible用户的已知主机中。您应该将github.com SSH密钥指纹添加到
/home/user/.SSH/known_hosts
文件中。幸运的是,
known_hosts
现在是Ansible 1.9中提供的一个模块:

如果您使用的是Ansible<1.9,则可以使用标准的
ssh-keygen
命令:

- shell: ssh-keygen -l -f /home/user/.ssh/known_hosts -F github.com
  register: github_host_is_known
- shell: ssh-keyscan -H github.com >> /home/user/.ssh/known_hosts 
  when: github_host_is_known|failed

运行
pip-install-git时会发生什么+ssh://git@github.com/mycompany/my repo.git#egg=0.1.0
手动?它工作正常,是的,很抱歉,我应该添加此信息,并且在bash之外运行命令时,也一样好,例如:未定义环境命令时?尝试
unset HOME
,然后再次运行pip命令。好吧,我刚刚意识到你的意思是在vagrant中运行该命令,我这么做了,并且在提示确认将github.com添加到已知主机列表后,该命令也起了作用,这就是设置最有可能挂起的原因
unset HOME
没有任何区别。好的,现在设置应该可以工作了。这可以工作,但我不希望在playbook中硬编码密钥,以免在playbook中硬编码密钥。您有在这种情况下使用ssh代理转发的示例吗?您可以选择使用哪个密钥生成主机吗
ssh-keycan
?你说的“哪个密钥”是什么意思?主机只有一个键=其标识。
- shell: ssh-keygen -l -f /home/user/.ssh/known_hosts -F github.com
  register: github_host_is_known
- shell: ssh-keyscan -H github.com >> /home/user/.ssh/known_hosts 
  when: github_host_is_known|failed