Ansible galaxy provisionner在Vagrant中没有使用私钥

时间:2016-06-23 11:01:48

标签: git ansible vagrant ssh-keys ansible-galaxy

我有以下vagrantfile

Vagrant.configure(2) do |config|

  config.ssh.insert_key = true
  config.vm.define "dev" do |app|
    app.vm.provider "docker" do |d|
      d.image = "allansimon/allan-docker-dev-python"
      d.has_ssh = true
    end

    app.ssh.username = "vagrant"

    app.vm.provision "file", source: "~/.ssh/id_rsa", destination: ".ssh/id_rsa"


    app.vm.provision "permits-root-to-clone", type: "shell" do |s|
      s.inline = "cp /home/vagrant/.ssh/id_rsa /root/.ssh/id_rsa"
    end
    # if i put here a new shell provisionner , to the exact same repo than in my galaxy roles , it works

    app.vm.provision "ansible_local" do |ansible|
      ansible.galaxy_role_file = "build_scripts/ansible/requirements.yml"
      ansible.playbook = "build_scripts/ansible/bootstrap.yml"
    end
  end
end

requirements.yml引用一些私有的ansible角色,即git-cloned

像这样

- src: git@gitlab.mydomain.com:ansible-roles/myrole.git
  scm: git
  version: 'master'
  name: myrole

我在流浪汉内注入我的桌面私钥

  • 适用于销售提供商
  • 如果在机器内vagrant ssh之后
  • ,它就有效

但它不适用于ansible_local配置程序 错误

==> dev: Running provisioner: ansible_local...
    dev: Running ansible-galaxy...
 [WARNING]: - supervisord was NOT installed successfully: - command git clone
git@gitlab.mydomain.com:ansible-roles/myrole.git myrole failed in
directory /tmp/tmpQNgCTo (rc=128)
ERROR! - you can use --ignore-errors to skip failed roles and finish processing the list.
Ansible failed to complete successfully. Any error output should be
visible above. Please fix these errors and try again.

有没有办法强制在vagrant中使用ansible来使用特定的私钥?

1 个答案:

答案 0 :(得分:0)

我认为这是因为ssh客户端无法找到您的私钥,或者无法在无用信息框中使用它来用于对git存储库进行身份验证(权限问题?)。您也许应该添加一个默认配置文件(~/.ssh/config)。

似乎可以确认,因为当您使用ssh连接到无业游民的盒子时,本地ssh客户端能够使用ssh-agent来获取密钥,该密钥与连接一起从台式机转发。

如果要手动调试

    在流浪者框中
  • ssh
  • 杀死ssh代理(ssh-agent -k
  • 手动(git clone git@gitlab.mydomain.com:ansible-roles/myrole.git)检索git存储库,或者尝试直接(ssh git@gitlab.mydomain.com)SSH,这可能会有所帮助
  • 发现错误