I have an issue related to running a box on OS X with a Vagrantfile/provision previously tested successfully on Windows. The box has the particularity of running Ansible entirely on the VM, but I think the problem comes way before.
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
config.vm.box = "ubuntu/trusty64"
config.vm.hostname = "rubicon.vm"
config.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", :id, "--cpus", "2" ]
vb.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/vagrant", "1"]
end
config.vm.network "forwarded_port", guest: 8888, host: 8888
config.vm.network "private_network", ip: "192.168.33.10"
config.vm.synced_folder ".", "/vagrant"
config.vm.provision :shell,
:keep_color => true,
:inline => "export PYTHONUNBUFFERED=1 && export ANSIBLE_FORCE_COLOR=1 && cd /vagrant && ./provision.sh"
end
I get an error at the provision step:
/tmp/vagrant-shell: line 1: ./provision.sh: Permission denied
To verify that (1) provision.sh was found and (2) the user should be root and have all permission, I modified the provision line with:
:inline => "cd /vagrant && ls -al && echo $USER && ./provision.sh"
The output was:
==> default: drwxr-xr-x 1 vagrant vagrant 204 Aug 12 10:06 .
==> default: drwxr-xr-x 23 root root 4096 Aug 12 10:12 ..
==> default: drwxr-xr-x 1 vagrant vagrant 136 Aug 11 14:28 ansible
==> default: -rw-r--r-- 1 vagrant vagrant 767 Aug 11 14:35 provision.sh
==> default: drwxr-xr-x 1 vagrant vagrant 102 Aug 11 14:30 .vagrant
==> default: -rwxr-xr-x 1 vagrant vagrant 785 Aug 12 10:06 Vagrantfile
==> default: root
==> default: /tmp/vagrant-shell: line 1: ./provision.sh: Permission denied
So nothing surprising there.
You need to grant execute permissions on provision.sh
chmod +x provision.sh
Related
I am having trouble connecting to Vagrant from the DB client tool (Datagrip).
If you know anything about this, we would appreciate it if you could let us know.
connection information
→ vagrant ssh-config
Host default
HostName 127.0.0.1
User bargee
Port 2222
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile /Users/〇〇/.vagrant/machines/default/virtualbox/private_key
IdentitiesOnly yes
LogLevel FATAL
SSH Connection with Terminal
$ ssh bargee#127.0.0.1 -p 2222 -i /Users/〇〇/.vagrant/machines/default/virtualbox/private_key
Welcome to Barge 2.15.0, Docker version 20.10.8, build 75249d8
[bargee#barge app]$
I was able to do it.
ssh connection on Datagrip
↓
Unable to connect.
Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "ailispaw/barge"
config.vm.box_version = "2.15.0"
config.vm.network "forwarded_port", guest: 3000, host: 3000
config.vm.synced_folder "./", "/app"
config.vm.provider :virtualbox do |vb|
vb.gui = false
vb.cpus = 4
vb.memory = 4096
vb.customize ['modifyvm', :id, '--natdnsproxy1', 'off']
vb.customize ['modifyvm', :id, '--natdnshostresolver1', 'off']
end
config.vm.provision "shell", inline: <<-SHELL
/etc/init.d/docker restart v20.10.8
wget "https://github.com/docker/compose/releases/download/v2.6.0/docker-compose-$(uname -s)-$(uname -m)" -O /opt/bin/docker-compose
chmod +x /opt/bin/docker-compose
if ! grep -q "cd /app" /home/bargee/.bashrc ; then
echo "cd /app" >> /home/bargee/.bashrc
fi
SHELL
end
Is there a way to get vagrant to loop through directories and take action on files?
I've just added this line to my Vagrantfile.
config.ssh.private_key_path = ".vagrant/machines/demo#{i}/virtualbox/private_key', '~/.ssh/id_rsa"
These are the other bits of the same Vagrantfile
(1..3).each do |i|
config.vm.define "demo#{i}" do |config|
config.vm.box = "bento/ubuntu-16.04"
config.vm.box_version = "202002.04.0"
config.vm.hostname = "demo#{i}"
config.vm.network :private_network, ip: "10.0.0.#{i + 10}"
config.vm.network :public_network, bridge: "en0: Wi-Fi (Wireless)"
config.ssh.forward_agent = true
config.vm.synced_folder '.', '/vagrant', disabled: true
config.vm.synced_folder "demo/shared", "/vagrant/shared"
config.vm.synced_folder "demo/dual", "/vagrant/dual"
config.ssh.private_key_path = ".vagrant/machines/demo#{i}/virtualbox/private_key, ~/.ssh/id_rsa"
config.vm.provider "virtualbox" do |vb|
vb.customize ["modifyvm", :id, "--cpuexecutioncap", "50"]
#vb.gui = true
vb.memory = "2096"
vb.cpus = "2"
end
end
end
end
But running vagrant reload errors with
* `private_key_path` file must exist: .vagrant/machines/demo1/virtualbox/private_key', '~/.ssh/id_rsa
Which is interesting as the path and file definitely exist.
pwd ; ls -R
/Users/xxx/.vagrant/machines
demo1 demo2 demo3
./demo1/virtualbox:
action_provision action_set_name box_meta creator_uid private_key id synced_folders
./demo2/virtualbox:
action_provision action_set_name box_meta creator_uid private_key id synced_folders
./demo3/virtualbox:
action_provision action_set_name box_meta creator_uid private_key id synced_folders
What I expect is for vagrant to just loop through each directory and read the files
Is there some way to get vagrant to do this?
So I found what was wrong with it.
I just needed to add extra quotes.
config.ssh.private_key_path = ".vagrant/machines/demo#{i}/virtualbox/private_key, ~/.ssh/id_rsa"
Becomes
config.ssh.private_key_path = ".vagrant/machines/demo#{i}/virtualbox/private_key", "~/.ssh/id_rsa"
And it works a charm.
The /vagrant directory is empty. It should contain the workspace where my Vagrantfile is located. I can cd /vagrant, but it's empty.
Vagrantfile
VAGRANTFILE_API_VERSION = '2'
VAGRANT_BOX_NAME = 'nomades.local'
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = 'bento/centos-6.7'
config.vm.box_check_update = false
config.vm.hostname = VAGRANT_BOX_NAME
config.vm.define VAGRANT_BOX_NAME do |dev|
dev.vm.provider 'virtualbox' do |v|
v.name = VAGRANT_BOX_NAME
v.memory = 512
v.cpus = 2
v.gui = true
v.customize ['modifyvm', :id, '--ioapic', 'on', '--vram', '16']
end
# Réseau (penser à configurer son /etc/hosts pointant vers cette ip)
dev.vm.network 'private_network', ip: '192.168.12.2'
# In order to use VPN
# dev.vm.network 'public_network', ip: '172.32.0.101'
# Provision
dev.vm.provision "ansible" do |ansible|
ansible.groups = {
'vagrant' => [VAGRANT_BOX_NAME],
'servers' => [VAGRANT_BOX_NAME],
}
ansible.playbook = 'provision/provision.yml'
ansible.sudo = true
end
end
end
This happens when vagrant can't modify /etc/fstab and tries to mount the current working directory from the host. Make sure it has permissions to mount the directory.
Run this on the Vagrant guest VM, then logout.
$ sudo /etc/init.d/vboxadd setup
Run this on the host.
$ sudo vagrant reload
$ vagrant ssh
This issue happened to me after manually rebooting the VM (i.e. sudo reboot).
Restarting the machine from the host solved the problem for me:
$ vagrant halt
$ vagrant up
you need to define below line in the vagrantfile, . means current directory
config.vm.synced_folder ".", "/vagrant"
How can I configure puppet to provision a user on the guest machine with a username that matches the username of the user on the host machine who provisions the guest? (Using puppet apply, not server/master)
$ puppet --version
3.4.3
$ vagrant --version
Vagrant 1.7.2
This is what I've tried so far:
Following the instructions in this SO answer I tried to use vagrant/puppet to create a user account on the guest machine which matches the user account on the host machine. But ultimately, it didn't work. Instead of getting the host username, a "$user_name" user was created.
Vagrantfile:
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "npalm/mint17-amd64-cinnamon"
config.vm.hostname = "dev-env"
config.vm.provider "virtualbox" do |vb|
vb.name = "dev-env"
vb.customize ["modifyvm", :id, "--cpus", "2"]
vb.customize ["modifyvm", :id, "--memory", "1280"]
end
config.vm.provision "shell", path: "provisioning/shell/apt-update.sh"
config.vm.provision "shell", path: "provisioning/shell/puppet.sh"
config.vm.provision "puppet" do |puppet|
puppet.facter = {
"user_name" => ENV['USER']
}
puppet.options = "--verbose --debug"
puppet.manifests_path = "provisioning/puppet/manifests"
puppet.module_path = "provisioning/puppet/modules"
end
end
provisioning/shell/apt-update.sh:
#!/usr/bin/env bash
sudo apt-get -y update
sudo apt-get install -y aptitude
provisioning/shell/puppet.sh:
#!/usr/bin/env bash
sudo aptitude install -y puppet
provisioning/puppet/manifests/default.pp:
user { '$user_name':
ensure => 'present',
comment => 'developer account',
home => '/home/$user_name',
shell => '/bin/bash',
uid => 643
}
->
file{'$user_name home':
ensure => 'directory',
path => '/home/$user_name',
owner => '$user_name',
group => '$user_name'
}
Actual Output
##############
# Host Machine
##############
$ whoami
axiopisty
###############
# Guest Machine
###############
$ ls -la /home/
total 16
drwxr-xr-x 4 root root 4096 Dec 17 23:41 .
drwxr-xr-x 24 root root 4096 Sep 28 20:41 ..
drwxr-xr-x 2 $user_name $user_name 4096 Dec 17 23:41 $user_name
drwxr-xr-x 13 vagrant vagrant 4096 Sep 28 20:42 vagrant
Expected Output
##############
# Host Machine
##############
$ whoami
axiopisty
###############
# Guest Machine
###############
$ ls -la /home/
total 16
drwxr-xr-x 4 root root 4096 Dec 17 23:41 .
drwxr-xr-x 24 root root 4096 Sep 28 20:41 ..
drwxr-xr-x 2 axiopisty axiopisty 4096 Dec 17 23:41 axiopisty
drwxr-xr-x 13 vagrant vagrant 4096 Sep 28 20:42 vagrant
Puppet will not resolve variable names when its simple quoted. To make sure interpolation of your variable names is done, you must use "; so the following in your puppet file will work
user { $user_name:
ensure => 'present',
comment => 'developer account',
home => "/home/$user_name",
shell => '/bin/bash',
uid => 643
}
->
file{"$user_name home":
ensure => 'directory',
path => "/home/$user_name",
owner => "$user_name",
group => "$user_name"
}
I'm following this link https://github.com/acfreitas/oraclebox
I tried to include the code for setting up VM storage size on my Vagrant.
But i'm getting error like below.
==> vagrant: Running provisioner: shell...
vagrant: Running: C:/Users/skywork/AppData/Local/Temp/vagrant-shell20151111-11660-1l3hhe.sh
==> vagrant: ++ '[' grep -ic 64GB /sizeDisk ']'
==> vagrant: /tmp/vagrant-shell: line 4: [: too many arguments
==> vagrant: ++ sudo fdisk -u /dev/sdb
==> vagrant: Welcome to fdisk (util-linux 2.23.2).
==> vagrant:
==> vagrant: Changes will remain in memory only, until you decide to write them.
==> vagrant: Be careful before using the write command.
==> vagrant:
==> vagrant:
==> vagrant: Command (m for help): Partition type:
==> vagrant: p primary (0 primary, 0 extended, 4 free)
==> vagrant: e extended
==> vagrant: Select (default p): Partition number (1-4, default 1): First sector (2048-31457279, default 2048): Using default value 2048
==> vagrant: Last sector, +sectors or +size{K,M,G} (2048-31457279, default 31457279): Last sector, +sectors or +size{K,M,G} (2048-31457279, default 31457279): Value out of range.
==> vagrant: Last sector, +sectors or +size{K,M,G} (2048-31457279, default 31457279): Last sector, +sectors or +size{K,M,G} (2048-31457279, default 31457279):
==> vagrant: Device does not contain a recognized partition table
==> vagrant: Building a new DOS disklabel with disk identifier 0x38d6fb65.
==> vagrant: Do you really want to quit?
The SSH command responded with a non-zero exit status. Vagrant
assumes that this means the command failed. The output for this command
should be in the log above. Please read the output to determine what
went wrong.
Here is my Vagrant file codes:
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION_NO = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION_NO) do |config|
config.vm.define "vagrant" do |oracle|
oracle.vm.box = "CentOS7"
oracle.vm.boot_timeout = 5000
oracle.vm.box_url = "http://zzz.zzz.zzz/CentOS7.1.1503x86_64.box"
oracle.ssh.username = "root"
oracle.ssh.password = "vagrant"
config.vbguest.auto_update = false
oracle.vm.synced_folder "./share", "/root/share", :create => true, type: "nfs"
oracle.vm.provider :virtualbox do |vb|
vb.gui = true
vb.name = "CentOS7"
vb.customize ["modifyvm", :id, "--memory", "2048", "--cpus", "1", "--nicpromisc2", "allow-all"]
vb.customize ["modifyvm", :id, "--natdnsproxy1", "off"]
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "off"]
vb.customize ["modifyvm", :id, "--name", "CentOS7"]
if !File.exist?("disk/oracle.vdi")
vb.customize [
'createhd',
'--filename', 'disk/oracle',
'--format', 'VDI',
'--size', 15360
]
vb.customize [
'storageattach', :id,
'--storagectl', "SATA",
'--port', 1, '--device', 0,
'--type', 'hdd', '--medium', 'disk/oracle.vdi'
]
end
end
oracle.vm.provision "shell", path: "bash_files/add-oracle-disk.sh"
oracle.vm.provision "shell", :inline => "localectl set-locale LANG=en_US.UTF-8"
oracle.vm.provision :chef_solo do |chef|
chef.custom_config_path = "Vagrantfile.chef"
chef.add_recipe "base"
end
end
end
Vagrant::Config.run do |config|
config.vm.network :bridged, auto_config: false
end
Here is my VM default disk size:
How and what value I need to put on my VagrantFile and add-oracle-disk.sh to be able to add disk space (10GB for example).
Please help.