git - Ansible:使用 pip 从私有(private) git repo 安装包

标签 git ssh pip ansible

我正在尝试以这种方式使用 ansible 的 pip 模块从私有(private) git 仓库安装一个包:

- name: Install my package
  pip: name='git+ssh://git@github.com/mycompany/my-repo.git#egg=0.1.0'
       virtualenv=/path/to/venv

但是当我尝试使用 vagrant 提供它时它挂起,很可能是因为它提示确认将 key 添加到已知主机列表。事实上,当我在 vagrant 中运行它时:

pip install git+ssh://git@github.com/mycompany/my-repo.git#egg=0.1.0

它提示确认将 github 添加到已知主机,然后工作正常。

如果我使用 accept_hostkey=yes 克隆它:

- name: Clone repo
  git: repo=git@github.com:mycompany/my-repo.git
       dest=/path/to/dest
       accept_hostkey=yes
       recursive=no

它工作正常,因为它接受在 vagrant 上复制的主机 key 。对于 pip 模块,没有这样的选项,有什么办法解决这个问题吗? 作为替代方案,我可以执行克隆,然后执行 python setup.py install,但我宁愿使用 pip 一步完成。

最佳答案

checkout 命令挂起,因为 github.com 不在您的 Ansible 用户的已知主机中。您应该将 github.com SSH key 指纹添加到 /home/user/.ssh/known_hosts 文件中。幸运的是,known_hosts 现在是 Ansible 1.9 中可用的模块: http://docs.ansible.com/known_hosts_module.html

- known_hosts: path=/home/user/.ssh/known_hosts name=github.com key="|1|ba0yHIHdbaD9nswn12xSOyD8DFE=|EVZBrcr46cYcmx6qFRIrzTvWUX4= ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ=="

如果您使用的是 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

关于git - Ansible:使用 pip 从私有(private) git repo 安装包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31118402/

相关文章:

git - 在 Gitlab 中回滚到以前的版本

emacs - 在 emacs 中的 term-mode 中,退格在 ssh 中不起作用

Windows 服务器上的 Laravel SSH

不包含在 "conda env export"中的 pip 包

Git 克隆在 Linux VM 上对 HTTPS 进行故障转移(膨胀 : Data Stream Error)

git - 如何自动生成提交信息

python - 虽然已经安装但无法导入 scipy

python - 模块未找到错误 : No module named 'tools.nnwrap' (macOS)

python - 如何处理 `relation "cms_disclaimerpanel"already exists` 和 ProgrammingError : column "http_request_lang" of relation "xyz" does not exist

java - "Could not load known_hosts"使用 SSHJ 的异常