无法在 Windows 上获取私有 GitHub 存储库以与 Vagrant/Puppet 配合使用

无法在 Windows 上获取私有 GitHub 存储库以与 Vagrant/Puppet 配合使用

我有一个项目,我们使用 Vagrant 作为开发环境。在 Mac/Unix 上,配置工作正常,但在 Windows 上除外,问题是转发代理在 Windows 上不起作用,因此我无法访问私有 GitHub 存储库。

我通过添加以下内容修复了此问题Vagrantfile

  # Windows github ssh keys fix
  if Vagrant::Util::Platform.windows?
    # You MUST have a ~/.ssh/github_rsa (GitHub specific) SSH key to copy to VM
    if File.exists?(File.join(Dir.home, ".ssh", "github_rsa"))
      # Read local machine's GitHub SSH Key (~/.ssh/github_rsa)
      github_ssh_key = File.read(File.join(Dir.home, ".ssh", "github_rsa"))
      # Copy it to VM as the /root/.ssh/id_rsa key
      config.vm.provision :shell, :inline => "echo 'Windows-specific: Copying local GitHub SSH Key to VM for provisioning...' && mkdir -p /root/.ssh && echo '#{github_ssh_key}' > /root/.ssh/id_rsa && chmod 600 /root/.ssh/id_rsa"
    else
      # Else, throw a Vagrant Error. Cannot successfully startup on Windows without a GitHub SSH Key!
      raise Vagrant::Errors::VagrantError, "\n\nERROR: GitHub SSH Key not found at ~/.ssh/github_rsa (required on Windows).\nYou can generate this key manually OR by installing GitHub for Windows (http://windows.github.com/)\n\n"
    end
 end

当将上述脚本添加到以下内容后,即可使用此 Puppet 脚本(最终可在 Windows 上运行)完成克隆Vagrantfile

class install_repos {
  vcsrepo { '/home/vagrant/git_project':
    ensure   => present,
    provider => git,
    source   => '[email protected]:proj_path',
    require => Class['known_hosts']
  }
}

在同一个文件中,我在 Gemfile 中有以下内容,其中一些 gem 指向 GitHub 存储库:

exec { 'install_project':
   command     => 'bundle install',
   cwd         => '/vagrant',
   provider    => 'shell',
   require     => [
      Class['install_ruby'],
      Class['known_hosts'],
      Class['install_repos'],
    ]
  }

bundle install如果我打开 SSH 到 vagrant 实例并测试我的 Github 连接,则总是失败,我得到以下信息:ssh -T [email protected]

Warning: Permanently added the RSA host key for IP address '192.30.252.130' to the list of known hosts.
Permission denied (publickey).

无论我怎么尝试,我都无法让它在 Windows 上运行,而且我不确定到底发生了什么。

相关内容