hashicorp / vagrant

Vagrant is a tool for building and distributing development environments.
https://www.vagrantup.com
Other
26.29k stars 4.43k forks source link

Issue with custom boxes using vagrant and vmware #11633

Open andycockers opened 4 years ago

andycockers commented 4 years ago

Vagrant version

2.2.9

Host operating system

Ubuntu Linux 18.04

Guest operating system

Ubuntu Linux 18.04

Vagrantfile

BACKEND_IMAGE = "4cplatform/4cngbackend"
BACKEND_VERSION = "1.0.4"
MYSQL_IMAGE = "4cplatform/4cngmysql"
MYSQL_VERSION = "1.0.4"
BACKEND_SRC = "src/4c-backend"
MYSQL_SRC = "src/4c-mysql"
CLIENT_BACKEND_SRC = "src/client-backend"
CLIENT_MYSQL_SRC = "src/client-mysql"
BACKEND_HOSTNAME = "4c-backend.4clocal"
MYSQL_HOSTNAME = "4c-mysql.4clocal"
CLIENT_BACKEND_HOSTNAME = "client-backend.4clocal"
CLIENT_MYSQL_HOSTNAME = "client-mysql.4clocal"
RSYNC_MOUNT_OPTIONS = ["uid=1000", "gid=1000"]
RSYNC_EXCLUDE = ["Vagrantfile", ".git/", ".idea/", "node_modules/", "vendor/"]
NFS_EXPORT_OPTIONS = ['rw','no_subtree_check','no_all_squash','async']
# NFS mount_options info:
# rw      : give rw permissions on mount(ed) drive
# noatime : prevents the modification of the last-updated timestamp on files
# vers=3  : version of NFS to use (v4 not good on MacOS)
# udp     : change from tcp(default) to udp because faster
# actimeo : time in seconds NFS will cache files for
NFS_MOUNT_OPTIONS = ['rw', 'vers=3', 'udp', 'actimeo=1', 'noatime', 'noacl', 'nolock']
# Script to migrate standard mysql install to shared volume
# Script to migrate standard mysql install to shared volume
$sql_script = <<-SCRIPT
if [[ -d /var/lib/mysql ]]
then
    service mysql stop
    # Don't wipe out any existing DB on subsequent provision
    if [[ ! "$(ls -A /home/vagrant/mysql)" ]]
    then
        mv -f /var/lib/mysql/* /home/vagrant/mysql
    fi
    rm -rf /var/lib/mysql
    sed -i 's#/var/lib/mysql#/home/vagrant/mysql#g' /etc/mysql/mysql.conf.d/mysqld.cnf
    echo 'alias /var/lib/mysql/ -> /home/vagrant/mysql/,' >> /etc/apparmor.d/tunables/alias
    service apparmor restart
    service mysql start
fi
SCRIPT
#########################################################################################
Vagrant.configure("2") do |config|
    # Check for hostmanager - can't install dyamically as this bit runs after VM subconfigurations
    unless Vagrant.has_plugin?("vagrant-hostmanager")
        puts 'Please install the hostmanager plugin with vagrant plugin install vagrant-hostmanager'
        exit
    end
    # suppress vmware warnings
    config.vm.provider "vmware_desktop" do |vmware|
        vmware.whitelist_verified = true
    end
    # mac specific
    if Vagrant.has_plugin?("vagrant-gatling-rsync") 
        config.gatling.latency = 0.2
    end
    # nfs-specific
    config.nfs.map_uid = 1000
    config.nfs.map_gid = 1000
    # Windows specific
    if Vagrant::Util::Platform.windows? then
        # install the windows NFS plugin if it's missing
        unless Vagrant.has_plugin?("vagrant-winnfsd")
            puts 'Installing vagrant-winnfsd plugin...'
            system('vagrant plugin install vagrant-winnfsd')
        end
        # map uid and guid
        config.winnfsd.uid = 1000
        config.winnfsd.gid = 1000
    end
    # keep the default ssh key for local
    config.ssh.insert_key = false
    # initialise hostmanager
    config.hostmanager.enabled = true
    config.hostmanager.manage_host = true
    config.hostmanager.manage_guest = true
    config.hostmanager.ignore_private_ip = true
    config.hostmanager.include_offline = true
    # 4c-backend
    config.vm.define "4c-backend" do |backend|
      backend.vm.base_mac = "00:0c:29:9f:fa:88"
      backend.vm.box = BACKEND_IMAGE
      backend.vm.box_version = BACKEND_VERSION
      backend.vm.hostname = BACKEND_HOSTNAME
      backend.vm.network "public_network"
      backend.vm.provider "vmware_desktop" do |v|
        v.gui = true
        # use public IP for ssh_info - this allows hostupdater to get the right IP
        v.ssh_info_public = true
        v.vmx["memsize"] = 2048
        v.vmx["numvcpus"] = 2
        v.linked_clone = false
      end
      if ENV['USE_RSYNC'] == 'yes'
        backend.vm.synced_folder File.expand_path(BACKEND_SRC), "/home/vagrant/src",
        type: "rsync",
        rsync__chown: true,
        owner: "vagrant",
        group: "vagrant",
        mount_options: RSYNC_MOUNT_OPTIONS,
        rsync__exclude: RSYNC_EXCLUDE,
        id: BACKEND_SRC
      else
        # NFS
        backend.vm.synced_folder BACKEND_SRC, "/home/vagrant/src",
        type: "nfs",
        linux__nfs_options: NFS_EXPORT_OPTIONS,
        mount_options: NFS_MOUNT_OPTIONS,
        id: BACKEND_SRC
      end
    end
    # 4c-mysql
    config.vm.define "4c-mysql" do |mysql|
      mysql.vm.base_mac = "00:0c:29:e5:75:57"
      mysql.vm.box = MYSQL_IMAGE
      mysql.vm.box_version = MYSQL_VERSION
      mysql.vm.hostname = MYSQL_HOSTNAME
      mysql.vm.network "public_network"
      mysql.vm.provider "vmware_desktop" do |v|
        v.gui = true
        # use public IP for ssh_info - this allows hostupdater to get the right IP
        v.ssh_info_public = true
        v.vmx["memsize"] = 2048
        v.vmx["numvcpus"] = 2
      end
      if ENV['USE_RSYNC'] == 'yes'
        mysql.vm.synced_folder File.expand_path(MYSQL_SRC), "/home/vagrant/mysql",
        type: "rsync",
        rsync__chown: true,
        owner: "vagrant",
        group: "vagrant",
        mount_options: RSYNC_MOUNT_OPTIONS,
        rsync__exclude: RSYNC_EXCLUDE,
        id: MYSQL_SRC
      else
        # NFS
        mysql.vm.synced_folder MYSQL_SRC, "/home/vagrant/mysql",
        type: "nfs",
        mount_options: NFS_MOUNT_OPTIONS,
        id: MYSQL_SRC
      end
      mysql.vm.provision "shell", inline: $sql_script
    end
    # client-backend
    config.vm.define "client-backend" do |clientbackend|
      clientbackend.vm.base_mac = "00:0c:29:5d:c9:58"
      clientbackend.vm.box = BACKEND_IMAGE
      clientbackend.vm.box_version = BACKEND_VERSION
      clientbackend.vm.hostname = CLIENT_BACKEND_HOSTNAME
      clientbackend.vm.network "public_network"
      clientbackend.vm.provider "vmware_desktop" do |v|
        v.gui = true
        # use public IP for ssh_info - this allows hostupdater to get the right IP
        v.ssh_info_public = true
        v.vmx["memsize"] = 2048
        v.vmx["numvcpus"] = 2
        v.linked_clone = false
      end
      if ENV['USE_RSYNC'] == 'yes'
        clientbackend.vm.synced_folder File.expand_path(CLIENT_BACKEND_SRC), "/home/vagrant/src",
        type: "rsync",
        rsync__chown: true,
        owner: "vagrant",
        group: "vagrant",
        mount_options: RSYNC_MOUNT_OPTIONS,
        rsync__exclude: RSYNC_EXCLUDE,
        id: CLIENT_BACKEND_SRC
      else
        # NFS
        clientbackend.vm.synced_folder CLIENT_BACKEND_SRC, "/home/vagrant/src",
        type: "nfs",
        linux__nfs_options: NFS_EXPORT_OPTIONS,
        mount_options: NFS_MOUNT_OPTIONS,
        id: CLIENT_BACKEND_SRC
      end
    end
    # client-mysql
    config.vm.define "client-mysql" do |clientmysql|
      clientmysql.vm.base_mac = "00:0c:29:6f:7a:26"
      clientmysql.vm.box = MYSQL_IMAGE
      clientmysql.vm.box_version = MYSQL_VERSION
      clientmysql.vm.hostname = CLIENT_MYSQL_HOSTNAME
      clientmysql.vm.network "public_network"
      clientmysql.vm.provider "vmware_desktop" do |v|
        v.gui = true
        # use public IP for ssh_info - this allows hostupdater to get the right IP
        v.ssh_info_public = true
        v.vmx["memsize"] = 2048
        v.vmx["numvcpus"] = 2
      end
      if ENV['USE_RSYNC'] == 'yes'
        clientmysql.vm.synced_folder File.expand_path(CLIENT_MYSQL_SRC), "/home/vagrant/mysql",
        type: "rsync",
        rsync__chown: true,
        owner: "vagrant",
        group: "vagrant",
        mount_options: RSYNC_MOUNT_OPTIONS,
        rsync__exclude: RSYNC_EXCLUDE,
        id: CLIENT_MYSQL_SRC
      else
        # NFS
        clientmysql.vm.synced_folder CLIENT_MYSQL_SRC, "/home/vagrant/mysql",
        type: "nfs",
        linux__nfs_options: NFS_EXPORT_OPTIONS,
        mount_options: NFS_MOUNT_OPTIONS,
        id: CLIENT_MYSQL_SRC
      end
      clientmysql.vm.provision "shell", inline: $sql_script
    end
end

Please note, if you are using Homestead or a different Vagrantfile format, we may be unable to assist with your issue. Try to reproduce the issue using a vanilla Vagrantfile first.

Debug output

Provide a link to a GitHub Gist containing the complete debug output: https://www.vagrantup.com/docs/other/debugging.html. The debug output should be very long. Do NOT paste the debug output in the issue, just paste the link to the Gist.

Expected behavior

Four boxes should have started, all with different ip addresses.

Actual behavior

Four boxes start, but 4c-backend and client-backend share the same ip address and 4c-mysql and client-mysql share the same ip address.

Steps to reproduce

  1. Using vmware workstation. Using hashicorp/bionic64 as a base box, create a new box and upload to Vagrant Cloud.

  2. Create a multi machine Vagrantfile using the new box for both boxes.

  3. vagrant up. You will see that although vagrant claims to set separate ip's for both boxes, it actually sets the same one. This can be verified using vagrant ssh-config

References

briancain commented 4 years ago

Hello! Thanks for opening an issue. When opening a new issue on the Vagrant project, we ask that everyone provide a gist containing the behavior you're seeing with the --debug flag included. This helps us figure out what's actually going on. Thanks!

vinay-4c commented 4 years ago

Hi there, For the above mentioned issue please find attached debug logs gathere vagrant_debug.log d while running the multi machine vagrant boxes.

Thanks,

briancain commented 4 years ago

Hey there,

I am going to close this due to lack of response from the original issue reporter. If this is still occurring, please open a new issue and follow the provided issue template that appears when you click the "New Issue" button. This will help us in getting a reproduction and fix. Thanks!

vinay-4c commented 4 years ago

The original reporter (Andrew) is no longer working with us but the issue still persists. Can you please look into this and investigate further. Thanks in advance.