Ansible:从私人git仓库

时间:2015-06-29 14:32:24

标签: 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配置它时,这会挂起,很可能是因为它提示确认将密钥添加到已知主机列表中。的确,当我在流浪汉中运行时:

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上复制的主机密钥。使用pip模块没有这样的选择,有什么方法吗? 作为替代方案,我可以做一个克隆,然后是python setup.py install,但我宁愿用pip一步完成。

3 个答案:

答案 0 :(得分:3)

checkout命令挂起,因为github.com不属于Ansible用户的已知主机。您应该将github.com SSH密钥指纹添加到/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

答案 1 :(得分:1)

运行此任务以将主机密钥添加到import javax.swing.JOptionPane; public class RecursiveAssignment { public static void main(String[] args) { double x, y; while (true) { try { x = Double.parseDouble(JOptionPane.showInputDialog("Enter a non-negative whole number")); System.out.println(x); } catch (NumberFormatException nfe) { System.out.println("That's not a number! try again!"); continue; } try { y = factorial(x); System.out.println(y); break; } catch (NotAWholeNumber nawn) { System.out.println("This is not a whole number! Try again."); continue; } } System.out.println("There it is"); } public static double factorial(double x) throws NotAWholeNumber { if (x == 1 || x == 0) { return 1; } System.out.println(x % 2); //it's not making it passed this location, when it should... Ive //been testing using 5 as my user input every time.. if (x % 2 != 1.0 || x % 2 != 0.0) { throw new NotAWholeNumber("not a whole number"); } else { double y = factorial(x - 1) * x; return y; } } } public class NotAWholeNumber extends Exception { public NotAWholeNumber(String message) { super(message); } } 文件中:

known_hosts

答案 2 :(得分:0)

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

您始终可以在"〜/ .ssh / authorized_keys"中手动授权主机密钥。在运行pip之前。

示例:

https://stackoverflow.com/a/24305223/315168

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

相关问题