I have a VM that I'm pulling down with vagrant and using a VERY basic vagrant file
Vagrant.configure(2) do |config|
# The most common configuration options are documented and commented below.
# For a complete reference, please see the online documentation at
# https://docs.vagrantup.com.
# Every Vagrant development environment requires a box. You can search for
# boxes at https://atlas.hashicorp.com/search.
config.vm.box = "vagrant-rhel-devel"
config.vm.network :private_network, ip: "192.168.33.101"
config.vm.synced_folder ".", "/vagrant"
config.ssh.username = "vagrant"
config.ssh.password = "vagrant"
config.vm.provider "virtualbox" do |vb|
# Display the VirtualBox GUI when booting the machine
# vb.gui = true
# Enable 3d Rendering
vb.customize ["modifyvm", :id, "--accelerate3d", "on"]
# Sets 32megs video ram, higher number here = more POWERS
vb.customize ["modifyvm", :id, "--vram", "32"]
# # Customize the amount of memory on the VM:
# vb.memory = "1024"
vb.name = "RedHat 3D"
end
end
My issue is that the vagrant user gets a home directory of /localhome/vagrant and I'd like him to have /home/vagrant as the home directory.
Is this something I'm able to change with provisioning or is it something that is set in the VM itself? I'm rather unskilled at the provisioning step at the moment so an example would be great.
The HOME directory has been set when the user has been created so this was done before the VM was packaged as vagrant box.
From there, you should be able to change that with
usermod -m -d /path/to/new/home/dir userNameHere
so in your case it would be
usermod -m -d /home/vagrant vagrant
check if you have existing files under the /localhome directory that would need to be copied into the new one (bash preferences file)
if you do not plan to destroy/create a bunch of new VM from this box, its not needed to add as provisioning; if you do plan to use this box and create lot of new VM, then it could make sense, you would just need to add an inline shell provision
Related
I have the following Vagrantfile:
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "centos/6"
config.vm.provision :shell, :path => "bootstrap.sh"
config.vm.network :forwarded_port, host: 8080, guest: 80
config.vm.network :forwarded_port, host: 3306, guest: 3306
config.vm.synced_folder "../../applications", "/var/www/html", :owner=>"apache", :group=>"apache"
config.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", :id, "--memory", 2048]
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
vb.name = "appserver"
end
end
Each time I run vagrant up (for first time, let's say that first I ran vagrant destroy -f) I end up with the following error:
==> default: Mounting shared folders...
default: /vagrant => E:/Development/vagrant/centos6
default: /var/www/html => E:/Development/applications/arx
Vagrant was unable to mount VirtualBox shared folders. This is usually
because the filesystem "vboxsf" is not available. This filesystem is
made available via the VirtualBox Guest Additions and kernel module.
Please verify that these guest additions are properly installed in the
guest. This is not a bug in Vagrant and is usually caused by a faulty
Vagrant box. For context, the command attempted was:
id -u apache
The error output from the command was:
id: apache: No such user
The error is pretty clear "apache user does not exists". As I am seeing this there is two or "three" ways to fix this:
By removing the :owner=>"apache", :group=>"apache" portion from the synced_folder. This is a BIG no, at least for me because if I remove them then the folder will be owned by vagrant which will/could cause issues while apache tries to read something from /var/www/html.
By commenting the line config.vm.synced_folder, getting up the box so everything gets installed and setup, then shutting down the box and getting up again with the line uncommented: it works but still an ugly solution
By forcing the provisioning to happen before anything gets mounted: the ideal solution.
Does any know if this is possible and if so how? I wasn't able to found anything regarding the 3rd solution :( if you have a better solution you're more than welcome to post here it might help me and others probably.
I have found this and this but is not helpful.
one potential solution would be to run apache as vagrant user.
In your /etc/httpd/conf you can replace the User and Group value as
User vagrant
Group vagrant
so you can continue sharing your folder with vagrant user and httpd will be run as vagrant user.
You can use numeric ids and then create an user
config.vm.synced_folder '${HOSTDIR}', '${EXPORTDIR}', type: "virtualbox", owner: '123', group: '456'
config.vm.provision :shell, inline: "useradd --system -g '456' -u '123' -d '${EXPORTDIR}' --shell /bin/false apache"
I have a small problem with setting up my working environment after upgrade to Ubuntu 18.04. Vagrant version is 2.0.0.
Vagrant File
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
# The most common configuration options are documented and commented below.
# For a complete reference, please see the online documentation at
# https://docs.vagrantup.com.
# Every Vagrant development environment requires a box. You can search for
# boxes at https://atlas.hashicorp.com/search.
config.vm.box = "debian/jessie64"
# config.vm.box = "ubuntu/xenial64"
# Disable automatic box update checking. If you disable this, then
# boxes will only be checked for updates when the user runs
# `vagrant box outdated`. This is not recommended.
# config.vm.box_check_update = false
# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine. In the example below,
# accessing "localhost:8080" will access port 80 on the guest machine.
# NOTE: This will enable public access to the opened port
config.vm.network "forwarded_port", guest: 80, host: 8888
# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine and only allow access
# via 127.0.0.1 to disable public access
# config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1"
# Create a private network, which allows host-only access to the machine
# using a specific IP.
# config.vm.network "private_network", ip: "192.168.33.10"
# Create a public network, which generally matched to bridged network.
# Bridged networks make the machine appear as another physical device on
# your network.
# config.vm.network "public_network"
# Share an additional folder to the guest VM. The first argument is
# the path on the host to the actual folder. The second argument is
# the path on the guest to mount the folder. And the optional third
# argument is a set of non-required options.
config.vm.synced_folder ".", "/vagrant-nfs", type: :nfs, mount_options: ['rw', 'vers=3', 'tcp', 'fsc' ,'actimeo=2']
config.bindfs.bind_folder "/vagrant-nfs", "/srv/bspotted.net/app", :owner => "vagrant", :group => "vagrant"
config.vm.network :private_network, ip: "192.168.33.15"
# Provider-specific configuration so you can fine-tune various
# backing providers for Vagrant. These expose provider-specific options.
# Example for VirtualBox:
#
# config.vm.provider "virtualbox" do |vb|
# # Display the VirtualBox GUI when booting the machine
# vb.gui = true
#
# # Customize the amount of memory on the VM:
# vb.memory = "1024"
# end
#
# View the documentation for the provider you are using for more
# information on available options.
config.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", :id, "--name", "bspotted", "--memory", "2048"]
end
# Define a Vagrant Push strategy for pushing to Atlas. Other push strategies
# such as FTP and Heroku are also available. See the documentation at
# https://docs.vagrantup.com/v2/push/atlas.html for more information.
# config.push.define "atlas" do |push|
# push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME"
# end
# Enable provisioning with a shell script. Additional provisioners such as
# Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
# documentation for more information about their specific syntax and use.
# config.vm.provision "shell", inline: <<-SHELL
# apt-get update
# apt-get install -y apache2
# SHELL
# Ansible provisioner.
config.vm.provision "ansible_local" do |ansible|
ansible.version = "2.3.2.0"
ansible.install_mode = "pip"
ansible.provisioning_path = "/srv/bspotted.net/app"
ansible.playbook = "orchestration/vagrant.yml"
ansible.verbose = "vvv"
end
end
For the record I have an older version Ubuntu 16.10 on my other laptop and everything is working properly, this is the output of the vagrant up --debug &> vagrant.log command here.
Everything fall apart when setup reach
==> default: Preparing to edit /etc/exports. Administrator privileges will be required...
==> default: Mounting NFS shared folders...
after aprox 5 minutes, it will show
The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!
mount -o vers=3,udp,rw,vers=3,tcp,fsc,actimeo=2 192.168.33.1:/home/copser/Documents/Bspotted /vagrant-nfs
Stdout from the command:
Stderr from the command:
mount.nfs: Connection timed out
Problem is solved after I've changed the version of nfs,
`config.vm.synced_folder ".", "/vagrant-nfs", type: :nfs, mount_options: ['rw', 'vers=3', 'tcp', 'fsc' ,'actimeo=2']`
to
config.vm.synced_folder ".", "/vagrant-nfs", type: :nfs, mount_options: ['rw', 'vers=4', 'tcp', 'fsc' ,'actimeo=2']
just to make it clear I've changed vers=3 to vers=4, and no everything is working fine. You can check my correspondence with vagrant contributors here.
During the configuration of Vagrant environment on my machine I've received this message:
Vagrant:
* Unknown configuration section 'disksize'.
It was shown after the plugin has already been installed.
Here is the vagrantfile:
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
# The most common configuration options are documented and commented below.
# For a complete reference, please see the online documentation at
# https://docs.vagrantup.com.
# Every Vagrant development environment requires a box. You can search for
# boxes at https://atlas.hashicorp.com/search.
config.vm.box = "bento/ubuntu-16.04"
config.disksize.size = '150GB'
config.vm.provider :virtualbox do |vb|
vb.gui = true
end
# Disable automatic box update checking. If you disable this, then
# boxes will only be checked for updates when the user runs
# `vagrant box outdated`. This is not recommended.
# config.vm.box_check_update = false
# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine. In the example below,
# accessing "localhost:8080" will access port 80 on the guest machine.
config.vm.network "forwarded_port", guest: 8888, host: 8887
# Create a private network, which allows host-only access to the machine
# using a specific IP.
config.vm.network :private_network, ip: "192.168.33.12"
config.vm.hostname = "dsvm"
# Create a public network, which generally matched to bridged network.
# Bridged networks make the machine appear as another physical device on
# your network.
# config.vm.network "public_network"
# Share an additional folder to the guest VM. The first argument is
# the path on the host to the actual folder. The second argument is
# the path on the guest to mount the folder. And the optional third
# argument is a set of non-required options.
config.vm.synced_folder "./shared_directory", "/shared_directory"
# Provider-specific configuration so you can fine-tune various
# backing providers for Vagrant. These expose provider-specific options.
# Example for VirtualBox:
#
config.vm.provider "virtualbox" do |vb|
# Display the VirtualBox GUI when booting the machine
#vb.gui = true
# Customize the amount of memory on the VM:
vb.memory = "4096"#"2048"
vb.customize ["modifyvm", :id, "--cableconnected1", "on"]
end
# View the documentation for the provider you are using for more
# information on available options.
# Define a Vagrant Push strategy for pushing to Atlas. Other push strategies
# such as FTP and Heroku are also available. See the documentation at
# https://docs.vagrantup.com/v2/push/atlas.html for more information.
# config.push.define "atlas" do |push|
# push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME"
# end
# Enable provisioning with a shell script. Additional provisioners such as
# Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
# documentation for more information about their specific syntax and use.
#config.ssh.username = 'root'
#config.ssh.password = 'vagrant'
#config.ssh.insert_key = 'true'
#fixing_scripts
config.vm.provision :shell, path: "./shared_directory/install_scripts/fixing_scripts.sh"
#install_various_tools
config.vm.provision :shell, path: "./shared_directory/install_scripts/install_various_tools.sh"
#install_java
config.vm.provision :shell, path: "./shared_directory/install_scripts/install_java.sh"
#finalize_instalations.sh
config.vm.provision :shell, path: "./shared_directory/install_scripts/finalize_instalations.sh"
# Install R:
config.vm.provision :shell, path: "./shared_directory/install_scripts/install_R.sh"
# Install Docker:
config.vm.provision :shell, path: "./shared_directory/install_scripts/install_docker.sh"
# Adjust size :
config.vm.provision :shell, path: "./shared_directory/install_scripts/adjust_size_1.sh"
config.vm.provision :shell, path: "./shared_directory/install_scripts/adjust_size_2.sh"
#config.vm.provision "shell", inline: <<-SHELL
# some bach commnads to run in 1st "vagrant up"
#SHELL
config.vm.provision "shell", run: "always", inline: <<-SHELL
sudo su -
source /root/.bashrc
sudo -H jupyter notebook --notebook-dir=/shared_directory --no-browser --ip=0.0.0.0 --port=1565 &
SHELL
#Vagrant.configure("2") do |config|
# config.vm.provision "chef_solo" do |chef|
# chef.add_recipe 'apt'
# chef.add_recipe ''
# end
#end
end
I've tried changing the capacity of disksize.size to a smaller size, but without success.
What could be the problem?
Thanks in advance
You need to install the plugin:
vagrant plugin install vagrant-disksize
I'm trying to create aliases that I can use in Vagrant any time I run the VM. I've found several sources on the web about it, but can't get it working. I tried making a .bash_profile in my synced folder, but that didn't work. I noticed if I run the command alias name="command" this will work, but only for the current session. Anyone know how to do this? I'm using macOS. Thanks for your help!
Here is my Vagrantfile:
# -*- mode: ruby -*-
# vi: set ft=ruby :
unless Vagrant.has_plugin?("vagrant-vbguest")
warn "\nWARNING: The vagrant-vbguest plugin should be installed or your shared folders might not mount properly!"
warn "You can do this by running the command 'vagrant plugin install vagrant-vbguest'.\n\n"
end
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "pype_vm"
config.vm.box_url = "https://.../pype_vm.json"
config.vm.network "private_network", ip: ""
config.vm.boot_timeout = 600
config.vm.provider "virtualbox" do |v|
# This forces VirtualBox to use the host's DNS resolver instead of
# VirtualBox's
v.customize ["modifyvm", :id, "", "on"]
# This enables the PAE/NX option, which resolved at least one user's
# issues with the VM hanging on boot
v.customize ["modifyvm", :id, "--pae", "on"]
# The RHEL VM was created with 2GB of memory to facilitate provisioning,
# but this is causing issues with certain workstations. This reduces
# the amount of memory allocated to the VM but should not impact development
# performance. The number is in MB and can be increased if desired.
v.memory = 1024
end
# Share an additional folder to the guest VM.
config.vm.synced_folder File.dirname(__FILE__), "/pype"
end
The details depend on the specific of the guest being run, but some notes:
Assuming the default user account is active for vagrant ssh, ensure that any dotfiles you wish to override are copied to /home/vagrant.
If overriding .bashrc, ensure that the remote shell is started with the interactive flag (if this is true, echo $- will include i).
If overriding .bash_profile, ensure that the remote shell is started as a login shell (if this is true, echo $- will include l).
I'm using Vagrant to create an Ubuntu 14.04 guest on my Windows 7 SP 1 PC. This has been working ok, but the performance of the guest is poor when accessing files that have been synchronized from the host. After doing some reading, I'm trying to make the synchronized folder an SMB share, however this is failing when I run 'vagrant up'
Note that I've upgraded to powershell 3.0, as documented in https://docs.vagrantup.com/v2/synced-folders/smb.html. I've also ensured that my guest has cifs-util installed as pointed out in https://github.com/mitchellh/vagrant/issues/4642. I'm using Vagrant 1.7.4 and VirtualBox 4.3.28
My Vagrantfile looks like this:
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "npt"
config.vm.provider "virtualbox" do |v|
v.customize ["modifyvm", :id, "--cpuexecutioncap", "90"]
v.customize ["modifyvm", :id, "--memory", "4096"]
v.customize ["modifyvm", :id, "--cpus", 2]
end
config.vm.synced_folder "\\", "/npt_root", type: "smb"
config.vm.provision :shell do |shell|
shell.inline = "puppet module install puppetlabs/vcsrepo --force"
end
config.vm.provision "puppet" do |puppet|
puppet.manifests_path = "puppet"
puppet.manifest_file = "basic_build_reqs.pp"
end
config.ssh.username = 'root'
config.ssh.password = 'vagrant'
config.ssh.insert_key = 'true'
end
And the output I am seeing is:
Z:\npt\vagrant>vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'npt'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: vagrant_default_1442502969737_66801
==> default: Preparing SMB shared folders...
default: You will be asked for the username and password to use for the SMB
default: folders shortly. Please use the proper username/password of your
default: Windows account.
default:
default: Username: tdj#DCL
default: Password (will be hidden):
Exporting an SMB share failed! Details about the failure are shown
below. Please inspect the error message and correct any problems.
Host path: Z:/
Stderr: System error 123 has occurred.
The filename, directory name, or volume label syntax is incorrect.
Error:
Stdout:
It looks like Vagrant has interpreted the relative path "\" I've given it and is coming up with "Z:/", with unix style slashes, which Windows is then failing to parse.
Note that I've tried replacing the relative path with the absolute path "Z:\", but I still see the same output on the "Host path" line
I suspect "\\" is the problem in the following line:
config.vm.synced_folder "\\", "/npt_root", type: "smb"
Could you try to put in a concrete foldername that you would like to share with your VM and test if it works?