Can't ssh to vagrant VMs using the insecure private key (vagrant 1.7.2)

前端 未结 5 1313
孤街浪徒
孤街浪徒 2020-12-04 12:18

I have a cluster of 3 VMs. Here is the Vagrantfile:

 # -*- mode: ruby -*-
# vi: set ft=ruby :


hosts = {
  \"host0\" => \"192.168.33.10\",
  \"host1\" =&         


        
5条回答
  •  悲&欢浪女
    2020-12-04 13:09

    If you are specifically using Ansible (not the Vagrant Ansible provisioner), you might want to consider using the vagrant dynamic inventory script from Ansible's repo:

    • https://github.com/ansible/ansible/blob/devel/contrib/inventory/vagrant.py

    Alternatively, you'd can handcraft your own script and dynamically build your own vagrant inventory file:

    SYSTEMS=$(vagrant status | grep running | cut -d ' '  -f1)
    
    echo '[vagrant_systems]' > vagrant.ini
    
    for SYSTEM in ${SYSTEMS}; do
      SSHCONFIG=$(vagrant ssh-config ${SYSTEM})
      IDENTITY_FILE=$(echo "${SSHCONFIG}" | grep -o "\/.*${SYSTEM}.*")
      PORT=$(echo "${SSHCONFIG}" | grep -oE '[0-9]{4,5}')
      echo "${SYSTEM} ansible_ssh_host=127.0.0.1 ansible_ssh_port=${PORT} ansible_ssh_private_key_file=${IDENTITY_FILE}" >> vagrant.ini
    done
    

    Then use ansible-playbook -i=vagrant.ini

    If you try to use the ~/.ssh/config, you'll have to dynamically create or edit existing entries, as the ssh ports can change (due to the collision detection in Vagrant).

提交回复
热议问题