puppet git 使用 vcsrepo 模块以用户身份克隆私人仓库

puppet git clone private repo as user with vcsrepo module

我正在使用无主 puppet 安装来配置我的开发箱,我需要克隆一个私人存储库,但 vcsrepo 不会 运行 作为特定用户,因此使用了错误的 ssh 密钥。

根据 vcsrepo docs 这应该 运行 作为我的非根用户:

vcsrepo { '/path/to/repo':
  ensure   => present,
  provider => git,
  source   => 'git://example.com/repo.git',
  user     => 'blake',
}

但每次它 运行s 我认为它仍然是 运行ning 作为 root 因为我得到这个错误:

Error: Execution of 'git clone git@github.com:private-org/private-repo.git /home/blake/code/private-repo' returned 128: Cloning into '/home/blake/code/private-repo'...
Host key verification failed.
fatal: Could not read from remote repository.

如果我手动执行 git clone 它工作得很好,所以我知道为我的用户帐户设置了正确的 ssh 密钥。

更新 1:

好的,我添加了 --debug 标志,但它并没有提供更多信息。

Debug: Executing 'git clone git@github.com:private-org/private-repo.git /home/blake/code/private-repo'

但我认为这与我的 'known_hosts' 文件有关。如果主机是已知的,它工作得很好,否则它会显示上面的错误。因此,我需要弄清楚如何填充 'known_hosts' 文件,以便 vcsrepo 命令起作用。

本例中的 Host key verification failed 错误与 'known_hosts' 文件中缺少主机有关。

如果你从命令行执行 git clone 它会提示你将主机条目添加到 'known_hosts' 文件,但如果 puppet 运行 git clone命令。

为了解决这个问题,我使用 file_line 类型通过 puppet 添加了 ssh-keyscan -t rsa github.com 的输出到我的 'known_hosts' 文件。我还在 .ssh/config 文件中关闭了 'HashKnownHosts'。