devopsgroup-io / vagrant-hostmanager

:pencil: A Vagrant plugin that manages hosts files within a multi-machine environment.
Mozilla Public License 2.0
1.46k stars 146 forks source link

hostmanager does not update /etc/hosts on centos7 guests #276

Closed bbaassssiiee closed 5 years ago

bbaassssiiee commented 5 years ago

Vagrant version

Vagrant 2.2.6

Host operating system

Darwin Kernel Version 18.7.0

Guest operating system

Centos 7.6

Vagrantfile

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

Vagrant.configure(2) do |config|

  # provision.yml runs on a vagrant up, packer.yml runs on packer build.
  config.vm.provision "ansible" do |ansible|
    ansible.playbook = "ansible/vagrant.yml"
    ansible.compatibility_mode = "2.0"
    ansible.galaxy_role_file = "ansible/requirements.yml"
    ansible.galaxy_roles_path = "ansible/roles"
    ansible.inventory_path = "ansible/inventory/vagrant.ini"
    ansible.verbose = "v"
   end

  # Preference order
  config.vm.provider "virtualbox"
  config.ssh.insert_key = false
  config.vm.box_check_update = true
  config.hostmanager.enabled = true
  config.hostmanager.manage_host = false
  config.hostmanager.manage_guest = true

  plugins = [
    "vagrant-vbguest",
    "vagrant-hostmanager"
  ]

  plugins_to_install = plugins.select { |plugin| not Vagrant.has_plugin? plugin }
  if not plugins_to_install.empty? and ARGV[0] != "plugin"
    puts "Installing plugins: #{plugins_to_install.join(' ')}"
    if system "vagrant plugin install #{plugins_to_install.join(' ')}"
      exec "vagrant #{ARGV.join(' ')}"
    else
      abort "Installation of one or more plugins has failed. Aborting."
    end
  end
  if Vagrant.has_plugin?("vagrant-vbguest")
    config.vbguest.auto_update = false
  end

  config.vm.define :'vagrant-fileserver', autostart: true, primary: true do |fileserver_config|
    fileserver_config.vm.box = "redesign/centos7"
    fileserver_config.vm.hostname = "vagrant-fileserver"
    fileserver_config.vm.network "private_network", ip: "192.168.10.4"
    fileserver_config.vm.network "forwarded_port", id: 'ssh', guest: 22, host: 2204, auto_correct: false
    fileserver_config.vm.network "forwarded_port", id: 'sftp', guest: 2299, host: 2299, auto_correct: false
    fileserver_config.vm.synced_folder ".", "/vagrant", id: "vagrant-root", disabled: false
    fileserver_config.vm.provider "virtualbox" do |vb|
      vb.name = "vagrant-fileserver"
      vb.gui = false
      vb.customize ["modifyvm", :id, "--memory", 512]
      vb.customize ["modifyvm", :id, "--vram", "64"]
    end
  end
  config.vm.define :'vagrant-bastion', autostart: true, primary: true do |jumphost_config|
    jumphost_config.vm.box = "redesign/centos7"
    jumphost_config.vm.hostname = "vagrant-bastion"
    jumphost_config.vm.network "private_network", ip: "192.168.10.5"
    jumphost_config.vm.network "forwarded_port", id: 'ssh', guest: 22, host: 2205, auto_correct: false
    jumphost_config.vm.synced_folder ".", "/vagrant", id: "vagrant-root", disabled: false
    jumphost_config.vm.provider "virtualbox" do |vb|
      vb.name = "vagrant-bastion"
      vb.gui = false
      vb.customize ["modifyvm", :id, "--memory", 512]
      vb.customize ["modifyvm", :id, "--vram", "64"]
    end
  end
end

Debug output

demo:infrastructure bas$ vagrant plugin update vagrant-hostmanager
Updating plugins: vagrant-hostmanager. This may take a few minutes...
All plugins are up to date.
demo:infrastructure bas$ vagrant plugin list
vagrant-hostmanager (1.8.9, global)
  - Version Constraint: > 0
vagrant-parallels (2.0.1, global)
  - Version Constraint: > 0
vagrant-vbguest (0.20.0, global)
  - Version Constraint: > 0
vagrant-vmware-desktop (2.0.3, global)
  - Version Constraint: > 0
demo:infrastructure bas$ vagrant hostmanager
[vagrant-hostmanager:guest] Updating hosts file on the virtual machine vagrant-fileserver...
[vagrant-hostmanager:guest] Updating hosts file on the virtual machine vagrant-bastion...
demo:infrastructure bas$ vagrant ssh vagrant-fileserver
Last login: Fri Nov 15 15:45:45 2019 from 10.0.2.2
-bash-4.2$ cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

Expected behavior

My hosts file should have the hosts

Actual behavior

Nothing changed

Steps to reproduce

1. 2. 3.

References

Are there any other GitHub issues (open or closed) that should be linked here? For example:

bbaassssiiee commented 5 years ago

This was my bas, my base image had too restricted KEKs and MACs in /etc/ssh/sshd_config