vagrant ssh和ssh.private_key_path无法正常工作

时间:2015-02-21 18:14:35

标签: vagrant

这是我的VagrantFile

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

    host_vars.each do |name|

        if name != "." and name != ".."

            config.vm.define name do |machine|

                data_host = YAML.load_file("#{dir}/../ansible/host_vars/#{name}")

                machine.vm.hostname = File.basename("#{name}")
                machine.vm.box = "ubuntu/trusty64"

                machine.vm.provider "virtualbox" do |v|
                    v.name = name
                    v.memory = 2048
                    v.cpus = 2
                end

                machine.vm.network "private_network", ip: "#{data_host['ansible_ssh_host']}"

                machine.ssh.forward_agent = true

                if VAGRANT_COMMAND != "up" 
                    machine.ssh.username = "#{data_allhost['default_ssh_user_info']['name']}"
                    machine.ssh.host = "#{data_host['ansible_ssh_host']}"
                    machine.ssh.private_key_path = ["#{data_allhost['security_path']}/#{data_allhost['default_ssh_user_info']['private_authorized_keys']}"]
                end

            end

        end

    end

    config.vm.provision :ansible do |ansible|
            ansible.playbook = "../ansible/provision.yml"
            ansible.verbose = "vvvv"
        ansible.inventory_path = "../ansible/inventory/development"
        ansible.raw_arguments = ["-u","#{data_allhost['default_ssh_user_info']['name']}"]
    end

end

我能够成功执行"流浪汉",没有任何问题......

如果我尝试以这种方式连接:

ssh <user>@<host ip> -i <path to private key>

这是成功的,我不会要求输入密码。

但是,如果我尝试通过

vagrant ssh

它不起作用。通过检查流浪日志:

 INFO ssh: Invoking SSH: ["cox@192.168.33.10", "-p", "2222", "-o", "Compression=yes", "-o", "DSAAuthentication=yes", "-o", "LogLevel=FATAL", "-o", "StrictHostKeyChecking=no", "-o", "UserKnownHostsFile=/dev/null", "-o", "IdentitiesOnly=yes", "-i", "/home/updiversity/Virtualboxes/fisher/vagrant/.vagrant/machines/local.datadevserver.com/virtualbox/private_key", "-o", "ForwardX11=yes", "-o", "ForwardX11Trusted=yes", "-o", "ForwardAgent=yes"]

很明显,vagrant没有向SSH命令传递正确的私钥路径,而是提供默认的路径......

这是一个错误吗?

0 个答案:

没有答案