vagrant ssh-config HostName changes post running a provisioning shell script??

194 views
Skip to first unread message

Shashank Korada

unread,
Feb 1, 2018, 3:45:27 PM2/1/18
to Vagrant

I am bringing up a VM using the vmware vagrant plugin and once the VM is up I run a shell script to provision the VM.

Prior to the script that runs, following is the ssh-config and other details

ssh-config

sudo vagrant ssh-config
==> test-vm: --- ESXi version    : VMware ESXi 6.5.0 build-4887370
Host test-vm
HostName 10.73.40.42
User vagrant
Port 22
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile /home/username/.vagrant.d/insecure_private_key
IdentitiesOnly yes
LogLevel FATAL
ForwardAgent yes

With this when I run vagrant ssh it does a ssh to the VM without being prompted for a password

sudo vagrant ssh

==> test-vm: --- ESXi version    : VMware ESXi 6.5.0 build-4887370
Welcome to Ubuntu 16.04.3 LTS (GNU/Linux 4.4.0-87-generic x86_64)

* Documentation:  https://help.ubuntu.com
* Management:     https://landscape.canonical.com
* Support:        https://ubuntu.com/advantage

0 packages can be updated.
0 updates are security updates.

vagrant@vagrant:~$   ===> PASSWORDLESS SSH

Now when my shell script runs , it create certain bridge and network interfaces within the VM and post the script I see that on running ssh-config, it has a different HostName

sudo vagrant ssh-config

Host test-vm
HostName 172.18.0.1 ===> CHANGED
User vagrant
Port 22
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile /home/username/.vagrant.d/insecure_private_key
IdentitiesOnly yes
LogLevel FATAL
ForwardAgent yes

Why does vagrant change the hostname. Due to this I am unable to do a passwordless ssh to the VM using 'vagrant ssh'

sudo vagrant ssh

vag...@172.18.0.1's password:  ====> PASSWORD PROMPT

Why does the HostName change here? Is there a way to do a passwordless ssh here?


Regards

Alvaro Miranda Aguilera

unread,
Feb 2, 2018, 4:56:56 AM2/2/18
to vagra...@googlegroups.com
vagrant will change the hostname if there is a config.vm.hostname = "something" in the Vagrantifle

otherwise it shouldn't

why you are running vagrant commands with sudo?


--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
---
You received this message because you are subscribed to the Google Groups "Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vagrant-up+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/acb28870-c17f-4579-8438-947924387b86%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Alvaro

Shashank Korada

unread,
Feb 2, 2018, 7:03:12 AM2/2/18
to Vagrant
Hi Alvaro,

This is my vagrant file and I havent set any config.vm.hostname in my Vagrantfile. 

When I checked the hostname on the VM , it shows as vagrant.

VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.ssh.forward_agent = true
    config.vm.box = "bento/ubuntu-16.04"
    config.vm.network "private_network", ip: '50.x.x.x'
    config.vm.provider :vmware_esxi do |v|
      v.esxi_hostname = '10.x.x.x.'
      v.esxi_username = 'root'
      v.esxi_password = 'secret'
      v.custom_vmx_settings = [['vhv.enable', 'TRUE']]
      v.vmname = test-vm
      v.memsize = 6000
      v.numvcpus = 2
      v.virtual_network = ["VM Network","VM Network"]
      #v.resource_pool = "/Vagrant"
    end
    config.vm.provision :shell do |s|
       s.path = /home/username/somescript.sh
    end
end

I bought DOWN the interface with ip 172.18.0.1 and the ssh-config now showed the public interface that it should have shown earlier.
No idea why this is happening.
To unsubscribe from this group and stop receiving emails from it, send an email to vagrant-up+...@googlegroups.com.



--
Alvaro

Reply all
Reply to author
Forward
0 new messages