ssh freeze while running vagrant up - ruby

I am trying to setup an RHCE lab on my machine. I've installed vagrant version Vagrant 2.1.4 and virtualbox 5 on ubuntu 16.04. I downloaded centos-7.0-x86_64.box from [https://computingforgeeks.com/how-to-addinstall-and-run-centos-7-vagrant-box-to-virtualbox-using-vagrant/][1]
I installed vagrant plugins vagrant plugin vagrant-vbguest && sahara
Here is my vagrant script
# -*- mode: ruby -*-
# vi: set ft=ruby :
server_disk='server.vdi'
desktop_disk='desktop.vdi'
Vagrant.configure(2) do |config|
config.vm.box = "centos/7"
config.vm.define "classroom" do |s|
s.vbguest.auto_update = false
s.vm.network "private_network", ip: "192.168.33.254"
s.vm.synced_folder ".", "/vagrant", disabled: true
#s.vm.synced_folder "../repos", "/repos", owner: "root", group: "root"
s.vm.synced_folder "scripts/classroom", "/usr/local/scripts", type: "rsync", owner: "root", group: "root"
s.vm.provision "shell", inline: <<-SHELL
chmod u+x /usr/local/scripts/classroom.sh
/usr/local/scripts/classroom.sh
SHELL
end
config.vm.define "server" do |a|
a.vbguest.auto_update = false
a.vm.provider "virtualbox" do |v|
unless File.exist?(server_disk)
v.customize ['createhd', '--filename', server_disk, '--size', 20 * 1024]
end
v.customize ['storageattach', :id, '--storagectl', 'IDE Controller', '--port', 1, '--device', 0, '--type', 'hdd', '--medium', server_disk]
end
a.vm.network "private_network", ip: "192.168.33.11"
a.vm.synced_folder ".", "/vagrant", disabled: true
a.vm.synced_folder "scripts/server", "/usr/local/scripts", type: "rsync", owner: "root", group: "root"
a.vm.provision "shell", inline: <<-SHELL
chmod u+x /usr/local/scripts/server.sh
/usr/local/scripts/server.sh
SHELL
end
config.vm.define "desktop" do |b|
b.vbguest.auto_update = false
b.vm.provider "virtualbox" do |v|
unless File.exist?(desktop_disk)
v.customize ['createhd', '--filename', desktop_disk, '--size', 20 * 1024]
end
v.customize ['storageattach', :id, '--storagectl', 'IDE Controller', '--port', 1, '--device', 0, '--type', 'hdd', '--medium', desktop_disk]
end
b.vm.network "private_network", ip: "192.168.33.10"
b.vm.synced_folder ".", "/vagrant", disabled: true
b.vm.synced_folder "scripts/desktop", "/usr/local/scripts", type: "rsync", owner: "root", group: "root"
b.vm.provision "shell", inline: <<-SHELL
chmod u+x /usr/local/scripts/desktop.sh
/usr/local/scripts/desktop.sh
SHELL
end
end
When I run sudo vagrant up
I get error
An error occurred in the underlying SSH library that Vagrant uses.
The error message is shown below. In many cases, errors from this
library are caused by ssh-agent issues. Try disabling your SSH
agent or removing some keys and try again.
If the problem persists, please report a bug to the net-ssh project.
timeout during server version negotiating
I am following this https://github.com/frezbo/lab .Please do help me.

Related

Vagrant up return 403 Forbidden error when installing ansible

When I run vagrant up on my Centos6, it shows this error:
==> w3package_v2: Running provisioner: ansible_local...
w3package_v2: Installing Ansible...
The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!
sudo rpm -i https://dl.fedoraproject.org/pub/epel/epel-release-latest-`rpm >-E %dist | sed -n 's/.*el\
([0-9]\).*/\1/p'`.noarch.rpm
Stdout from the command:
Stderr from the command:
curl: (22) The requested URL returned error: 403 Forbidden
error: skipping https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
Below is Vagrantfile:
VAGRANTFILE_API_VERSION = "2"
APP_NAME = "w3package_v2"
VM_NAME = "w3package_v2"
GUEST_IP = "192.168.33.59"
# [note]
# * for VirtualBox users:
# vagrant-vbguest plugin required.
# Run `vagrant plugin install vagrant-vbguest`.
# * for Windows10 + Hyper-V users:
# Enable SMB 1.0 (for Windows 10 + Hyper-V users)
if !Object.const_defined?('VagrantVbguest') || !Vagrant.has_plugin?('vagrant-vbguest')
puts "ERROR: vagrant-vbguest plugin is required. Run `vagrant plugin install vagrant-vbguest`."
abort
end
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.define VM_NAME
config.vm.box = "bento/centos-6"
config.vm.boot_timeout = 3600
config.vm.network :private_network, ip: GUEST_IP
config.vm.network :public_network, bridge: 'en0: Wi-Fi (AirPort)'
if OS.windows?
config.vm.synced_folder ((File.expand_path(File.dirname(__FILE__) + "/../../../..")).gsub("/","\\")), "/var/www/" + APP_NAME + "/current", owner: "vagrant", type: "virtualbox", automount: true, SharedFoldersEnableSymlinksCreate: true
else
config.vm.synced_folder "../../../..", "/var/www/" + APP_NAME + "/current", id: "vagrant", nfs: true
end
config.ssh.insert_key = false
config.ssh.private_key_path = "~/.vagrant.d/insecure_private_key"
config.vm.provider :virtualbox do |vb|
vb.name = VM_NAME
vb.customize ["modifyvm", :id, "--memory", "2048"]
vb.customize ["modifyvm", :id, "--cpuexecutioncap", "100"]
vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
vb.customize ["setextradata", :id, "VBoxInternal/Devices/VMMDev/0/Config/GetHostTimeDisabled", 0]
if OS.windows?
vb.customize ["sharedfolder", "add", :id, "--name", VM_NAME, "--hostpath", (("//?/" + File.expand_path(File.dirname(__FILE__) + "/../../../..")).gsub("/","\\"))]
vb.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/" + VM_NAME, "1"]
config.vm.provision "shell", path: "../../configuration/vagrant-vbmount.sh", args: VM_NAME
end
end
config.vm.provider :hyperv do |h, override|
h.enable_virtualization_extensions = true
h.linked_clone = true
override.vm.synced_folder ((File.expand_path(File.dirname(__FILE__) + "/../../../..")).gsub("/","\\")), "/var/www/" + APP_NAME + "/current", type: "smb", automount: true, SharedFoldersEnableSymlinksCreate: true
end
config.vm.provision "ansible_local" do |ansible|
ansible.limit = "all"
ansible.compatibility_mode = "2.0"
ansible.playbook = "/var/www/" + APP_NAME + "/current/tools/provisioning/configuration/vagrant-local.yml"
ansible.verbose = "v"
end
end
## ref https://qiita.com/dd511805/items/8cb7e524e0d790c24af1
module OS
def OS.windows?
(/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil
end
end
And this is my main.yml file:
- name: check dir /var/www
shell: '[ -e /var/www ]; echo $?'
register: result
- name: mkdir /var/www
command: mkdir /var/www
when: result.stdout != '0'
- name: change locale
shell: 'cp /usr/share/zoneinfo/Japan /etc/localtime'
- name: install python-selinux
yum: pkg=libselinux-python state=latest
- name: disable selinux
selinux: state=disabled
- name: install epel-repo
yum: pkg=epel-release state=latest
- name: fix CentOS-Base.repo
template: src=CentOS-Base.repo dest=/etc/yum.repos.d/CentOS-Base.repo
- name: update yum
yum: name=* state=latest
How could I fix that?

storage-attach id different from the vagrant customisation id

I am using vagrant and ubuntu16.04 .
When i ran vagrant up i got the error as
A customization command failed:
["storageattach", :id, "--storagectl", "IDE Controller", "--port", 1, "--device", 0, "--type", "hdd", "--medium", "server.vdi"]
The following error was experienced:
#<Vagrant::Errors::VBoxManageError: There was an error while executing `VBoxManage`, a CLI used by Vagrant
for controlling VirtualBox. The command and stderr is shown below.
Command: ["storageattach", "538c4e03-f4ea-4adf-af6e-02d303d56f13", "--storagectl", "IDE Controller", "--port", "1", "--device", "0", "--type", "hdd", "--medium", "server.vdi"]
Stderr: VBoxManage: error: Could not find a controller named 'IDE Controller'
>
Please fix this customization and try again.
There seems to be conflict between the id generated by script and virtualbox machines one.
My Vagrant file is
# -*- mode: ruby -*-
# vi: set ft=ruby :
server_disk='server.vdi'
desktop_disk='desktop.vdi'
Vagrant.configure(2) do |config|
config.vm.box = "centos/7"
config.vm.define "classroom" do |s|
s.vbguest.auto_update = false
s.vm.network "private_network", ip: "192.168.33.254"
s.vm.synced_folder ".", "/vagrant", disabled: true
#s.vm.synced_folder "../repos", "/repos", owner: "root", group: "root"
s.vm.synced_folder "scripts/classroom", "/usr/local/scripts", type: "rsync", owner: "root", group: "root"
s.vm.provision "shell", inline: <<-SHELL
chmod u+x /usr/local/scripts/classroom.sh
/usr/local/scripts/classroom.sh
SHELL
end
config.vm.define "server" do |a|
a.vbguest.auto_update = false
a.vm.provider "virtualbox" do |v|
unless File.exist?(server_disk)
v.customize ['createhd', '--filename', server_disk, '--size', 20 * 1024]
end
v.customize ['storageattach', :id, '--storagectl', 'IDE Controller', '--port', 1, '--device', 0, '--type', 'hdd', '--medium', server_disk]
end
a.vm.network "private_network", ip: "192.168.33.11"
a.vm.synced_folder ".", "/vagrant", disabled: true
a.vm.synced_folder "scripts/server", "/usr/local/scripts", type: "rsync", owner: "root", group: "root"
a.vm.provision "shell", inline: <<-SHELL
chmod u+x /usr/local/scripts/server.sh
/usr/local/scripts/server.sh
SHELL
end
config.vm.define "desktop" do |b|
b.vbguest.auto_update = false
b.vm.provider "virtualbox" do |v|
unless File.exist?(desktop_disk)
v.customize ['createhd', '--filename', desktop_disk, '--size', 20 * 1024]
end
v.customize ['storageattach', :id, '--storagectl', 'IDE Controller', '--port', 1, '--device', 0, '--type', 'hdd', '--medium', desktop_disk]
end
b.vm.network "private_network", ip: "192.168.33.10"
b.vm.synced_folder ".", "/vagrant", disabled: true
b.vm.synced_folder "scripts/desktop", "/usr/local/scripts", type: "rsync", owner: "root", group: "root"
b.vm.provision "shell", inline: <<-SHELL
chmod u+x /usr/local/scripts/desktop.sh
/usr/local/scripts/desktop.sh
SHELL
end
end
VBoxManage list vms
gives output as
"ubuntu-server" {bc38335e-ddf7-48a1-b0be-3df2495b91df}
On changing the IDECONTROLLER to IDE the issue was fixed

Login as root to shell using ruby script

I want to login as root and run the remaining script
for that i used
system 'sudo su' but it fails.Here is the ruby script.
My requirement is to login as root on the system by prompting for password and then become the root user and run the remaining script.Please help me i am new to ruby
# -*- mode: ruby -*-
# vi: set ft=ruby :
server_disk='server.vdi'
desktop_disk='desktop.vdi'
Vagrant.configure(2) do |config|
config.vm.box = "centos/7"
config.vm.define "classroom" do |s|
s.vbguest.auto_update = false
s.vm.network "private_network", ip: "192.168.33.254"
s.vm.synced_folder ".", "/vagrant", disabled: true
#s.vm.synced_folder "../repos", "/repos", owner: "root", group: "root"
s.vm.synced_folder "scripts/classroom", "/usr/local/scripts", type: "rsync", owner: "root", group: "root"
s.vm.provision "shell", inline: <<-SHELL
chmod u+x /usr/local/scripts/classroom.sh
/usr/local/scripts/classroom.sh
SHELL
end
system 'sudo su'
config.vm.define "server" do |a|
a.vbguest.auto_update = false
a.vm.provider "virtualbox" do |v|
unless File.exist?(server_disk)
v.customize ['createhd', '--filename', server_disk, '--size', 20 * 1024]
end
v.customize ['storageattach', :id, '--storagectl', 'IDE Controller', '--port', 1, '--device', 0, '--type', 'hdd', '--medium', server_disk]
end
a.vm.network "private_network", ip: "192.168.33.11"
a.vm.synced_folder ".", "/vagrant", disabled: true
a.vm.synced_folder "scripts/server", "/usr/local/scripts", type: "rsync", owner: "root", group: "root"
a.vm.provision "shell", inline: <<-SHELL
chmod u+x /usr/local/scripts/server.sh
/usr/local/scripts/server.sh
SHELL
end
config.vm.define "desktop" do |b|
b.vbguest.auto_update = false
b.vm.provider "virtualbox" do |v|
unless File.exist?(desktop_disk)
v.customize ['createhd', '--filename', desktop_disk, '--size', 20 * 1024]
end
v.customize ['storageattach', :id, '--storagectl', 'IDE Controller', '--port', 1, '--device', 0, '--type', 'hdd', '--medium', desktop_disk]
end
b.vm.network "private_network", ip: "192.168.33.10"
b.vm.synced_folder ".", "/vagrant", disabled: true
b.vm.synced_folder "scripts/desktop", "/usr/local/scripts", type: "rsync", owner: "root", group: "root"
b.vm.provision "shell", inline: <<-SHELL
chmod u+x /usr/local/scripts/desktop.sh
/usr/local/scripts/desktop.sh
SHELL
end
end

Vagrant Synced Folders not showing

I want to sync my OSX dev folder which contains my applications to my VM. My VagrantFile (based off Phansible):
Vagrant.require_version ">= 1.5"
Vagrant.configure("2") do |config|
config.vm.provider :virtualbox do |v|
v.name = "default"
v.customize [
"modifyvm", :id,
"--name", "default",
"--memory", 512,
"--natdnshostresolver1", "on",
"--cpus", 1,
]
end
config.vm.box = "ubuntu/trusty64"
config.vm.network :private_network, ip: "192.168.33.99"
config.ssh.forward_agent = true
if which('ansible-playbook')
config.vm.provision "ansible" do |ansible|
ansible.playbook = "ansible/playbook.yml"
ansible.inventory_path = "ansible/inventories/dev"
ansible.limit = 'all'
ansible.extra_vars = {
private_interface: "192.168.33.99",
hostname: "default"
}
end
else
config.vm.provision :shell, path: "ansible/windows.sh", args: ["default"]
end
config.vm.synced_folder "/Users/xylar/Code", "/vagrant", type: "nfs"
end
When I vagrant up:
==> default: Exporting NFS shared folders...
==> default: Preparing to edit /etc/exports. Administrator privileges will be required...
==> default: Mounting NFS shared folders...
==> default: Running provisioner: ansible...
There are no error messages and when I vagrant ssh and view contents of the vagrant folder I only see some dot files (ansible, bash etc). Is there something I have missed?
I was being foolish. Once I had ssh'd into the box I thought I was in the synced folder (as it was called vagrant) however I was in /home/vagrant and the synced location was in /vagrant.
You need to specify the mount options:
config.vm.synced_folder "/Users/xylar/Code", "/vagrant", "nfs" => { :mount_options => ['dmode=777', 'fmode=777'] }

Strange vagrant shared folder issue -> can not "rm -rf"

My Vagrantfile:
Vagrant.configure("2") do |config|
config.vm.provider "virtualbox" do |v|
v.name = "web_vm"
v.customize ["modifyvm", :id, "--memory", "1024"]
#v.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/web_vm", "1"]
end
config.vm.box = "ubuntu/trusty64"
config.vm.network :forwarded_port, host: 81, guest: 80, auto_correct: true
config.vm.network :forwarded_port, host: 6612, guest: 3306, auto_correct: true
config.vm.synced_folder "src/", "/var/www", owner: "vagrant", group: "vagrant", :mount_options => ["dmode=777,fmode=777"]
config.vm.provision :shell, path: "bootstrap.sh"
end
As you can see, The "src" folder is accessible in vagrant as "/var/www". However, there seem to be sync problems: I am trying to remove a folder which is shown empty where it is not when you cross-check with the Windows Explorer.
Any idea what is happening here?
I have the same issue, but it seemed to be resolved by increasing the max_user_watches - variable for inotify:
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
My guess was that this had to to with the amount of files in the shared folder, and how vagrant has implemented the shared folder functionality.

Resources