Can't provision my Vagrant VM : Bad Interpreter (Chef solo - ruby) - ruby

This is the first time I'm using Vagrant, trying to get a debian machine set up with Java, Elasticsearch and Nginx!
But I can't provision my vm. Here is the issue I have:
==> default: Running provisioner: chef_solo...
Generating chef JSON and uploading...
Running chef-solo...
stdin: is not a tty
bash: /usr/bin/chef-solo: /usr/bin/ruby: bad interpreter: No such file or directory
Chef never successfully completed! Any errors should be visible in the
output above. Please fix your recipes so that they properly complete.
I don't know why it keeps telling me that chef-solo and ruby are located at those places because it's not the case. Is it on the client machine or on the host machine ?
I tried to change locations but didn't change the error message.
Here is my Vagrantfile
Any idea guys?

Related

Issues w vagrant ssh: terminating, 1 bad configuration options

first off I'm very new to programming and web development. I'm currently working through a Udacity course on SQL.
I'm trying to install VM and Vagrant and have run into this issue. Vagrant installed fine, and I'm able to run vagrant up, but when I run vagrant ssh I'm getting this message:
.ssh/config: terminating, 1 bad configuration options
I'll attach a screen here.
I'm on a Mac. Big Sur 11.5.2
Vagrant version 2.2.18
Any help provided would be greatly appreciated! Thanks in advance![enter image description here][1]
bash-3.2$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Checking if box 'bento/ubuntu-16.04-i386' version '2.3.5' is up to date...
==> default: Machine already provisioned. Run vagrant provision or use the --provision
==> default: flag to force provisioning. Provisioners marked to run always will still run.
bash-3.2$ vagrant ssh
/Users/scott27/.ssh/config: terminating, 1 bad configuration options
bash-3.2$
Consider moving your config file to a backup and trying again.
mv /Users/scott27/.ssh/config /Users/scott27/.ssh/config.bak
Then try vagrant up again and if it works then the issue is in your config file, troubleshoot that separately.
Instead of moving the existing ssh config file it is better to instead let vagrant point to its own config file using the config.ssh.config in vagrantfile
I am on Windows but I assume it is similar on mac. I updated my Vagrantfile like so:
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.ssh.config = File.expand_path(File.dirname(__FILE__) + '/ssh_config')
As you can see I point to a ssh_config file that I created, since an empty string resulted in an error.

How can I programmatically query Vagrant for its provisioning status?

The Goal
I am attempting to conditionally run the vagrant-berkshelf plugin. By default, enabling the plugin causes Berkshelf to resolve and vendor cookbooks on every single vagrant up (which is a relatively expensive operation) even if the current vagrant operation isn't a provisioning run. For example, I expect Berkshelf to run when I run:
vagrant up the first time, or
when I execute vagrant reload --provision.
The source implies there ought to be a way to query Vagrant itself to determine if it's a provisioning run. Specifically, there ought to be a way to hook into #env[:provision_enabled] or vagrant.actions.vm.provision, but I'm unable to figure out how to do this from within the Vagrantfile itself.
Is this method actually bound to the Vagrant object? If not there, then where? And how can I introspect it?
Software Versions
Vagrant 1.8.1
vagrant-berkshelf 4.1.0
What I've Tried
As a workaround, I have tried moving the Berkshelf plugin inside the Chef block, intending that it only run when the Chef provisioner does. For example:
Vagrant.configure(2) do |config|
config.berkshelf.enabled = false
config.vm.provision :chef_solo do |chef|
config.berkshelf.enabled = true
end
end
However, Berkshelf still runs every time I vagrant up or vagrant reload, which is not the desired behavior. The cookbooks are still resolved and vendored on each run. Consider the following elided output:
==> default: Updating Vagrant's Berkshelf...
==> default: Resolving cookbook dependencies...
==> default: Using karaf (0.2.1)
==> default: Vendoring karaf (0.2.1) to /Users/foo/.berkshelf/vagrant-berkshelf/shelves/berkshelf20160215-19428-unzcx1-default/karaf
Questions That Aren't Duplicates of This One
There is a vaguely related question where the accepted answer is an ugly hack that looks for the presence of .vagrant/machines/default/virtualbox/action_provision or similar, but it is not an exact duplicate of this question as it doesn't address how to programmatically query Vagrant's internal state through the runtime objects or API Vagrant exposes. It may hold a pragmatic (if kludgey) answer based on filesystem semaphores, but it does not answer the question I'm actually asking.
If it's possible for you to provision using vagrant provision instead of the --provision flag you can check with the following code in Vagrantfile:
if ARGV[0] == 'provision'
# Run berkshelf plugin
end
The code inside the conditional will only run on vagrant provision. This won't work when using vagrant reload with the --provision flag as you were saying, but you could simply run vagrant provision after running vagrant reload. You can also use if ARGV[0] == 'up' or if ARGV[0] == 'reload' to run when using other commands.
See: Getting command line arguments inside the Vagrantfile

Vagrant halt is failing with _syntax error near unexpected token `||'_

Vagrant is not able to halt / reload after the initial vagrant up (ie the one where the vm is provisioned). The initial vagrant up completes correctly, however after that I am not able to do the vagrant halt or reload.
The error message that I am getting is
==> default: Attempting graceful shutdown of VM...
The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!
shutdown -h now
Stdout from the command:
Stderr from the command:
stdin: is not a tty
bash: line 2: syntax error near unexpected token `||'
bash: line 2: `export SSH_AUTH_SOCK= || ||'
List of vagrant plugin I am using
- vagrant-proxyconf (1.5.2)
- vagrant-share (1.1.5, system)
Vagrant version is 1.8.1
Virtualbox [provider] version 4.3.34r104062
Host OS : Windows 7 Enterprise
I have tried re-installing, all the components, destroying the VMs, deleting the config files [ie ~/.VirtualBox & ~/.vagrant.d]
Please help me in resolving the issue
This is not the fix.
The error went away when I again downloaded the code base from github.

Error after `vagrant halt; vagrant up`

I am setting up a Ubuntu 15.04 VM on Win7 using Vagrant 1.7.4 and VBox 5.0.0.
On the first vagrant up I can ssh into the machine using vagrant putty and everything is setup correctly and works. When I run vagrant halt, the VM shuts down gracefully without error messages.
However, when I try to restart the VM using vagrant up; vagrant putty, the machine is in a strange state. For example, the default synced folder /vagrant is empty, even though the second vagrant up call prints this message:
default: /vagrant => C:/Users/ArneUser/numecs/dev_env
Also, this vagrant up call prints the following message in PowerShell:
The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!
/sbin/initctl emit --no-wait vagrant-mounted MOUNTPOINT=
Stdout from the command:
Stderr from the command:
stdin: is not a tty
bash: line 2: /sbin/initctl: No such file or directory
I am running a really basic setup just to test for this error, so I don't think the mistake is in my provisioning script. Some pointers in the right direction would be appreciated.
Open VirtualBox GUI and turn off machine manually, then run again the vagrant up command.
That solved the problem in my case :)
/vagrant is empty
/sbin/initctl emit --no-wait vagrant-mounted MOUNTPOINT=
From these two lines I suspect that MOUNTPOINT should be /vagrant but its due to /vagrant being empty that SSH is now working.
I've seen similar issues because of Virtualbox 5.
Try to downgrade Virtualbox to 4.3.x and ensure you have the latest Vagrant (1.7.4).
https://github.com/mitchellh/vagrant/issues/5572
Initctl is part of the Upstart init daemon. As far as I'm aware Ubuntu 15.04 is the first version of Ubuntu to abandon Upstart in favor of SystemD, so /sbin/initctl isn't expected to exist in your operating system. I believe this would need to be something that is fixed in the box you're using.
The point of "/sbin/initctl emit ..." is to notify other Upstart units that the vagrant shared folder has been mounted and is available for read/write operations. Since upstart is no longer in use it may be safe to assume that there is no need for this call. It's a rather crude hack, but you could make an empty script at /sbin/initctl. This should allow the vagrant startup process to continue properly and provision your box.
In my case it seems as Marc Young suggested that by opening Virtualbox GUI, the virtual machine itself seems to be hung. I saw these error messages on the virtual box console:
Thus it seems to not to be Vagrant related problem, but the virtual machine (Linux Kernel) itself seems to be hung.

vagrant package command fails

I am trying to create a vagrant box of a VirtualBox Ubuntu VM on my MacBook Pro. When I run the command I get an error that I don't understand. I've tried rebuilding the virtual machine. I've tried different virtual machines in different states. I keep hitting this brick wall.
It looks like VBoxManage tries to create a temporary file for the package process, but the file can't be written for some reason. This also happened on my Ubuntu laptop. So that's really interesting and makes me wonder if it is a problem with VBoxManage itself, however, it doesn't seem that many people are having this specific issue (though the error code "code VBOX_E_FILE_ERROR (0x80bb0004)" is relatively common.)
Here is the output of my command:
earthmant$ vagrant package --base 64precise6
==> 64precise6: Attempting graceful shutdown of VM...
64precise6: Guest communication could not be established! This is usually because
64precise6: SSH is not running, the authentication information was changed,
64precise6: or some other networking issue. Vagrant will force halt, if
64precise6: capable.
==> 64precise6: Forcing shutdown of VM...
==> 64precise6: Exporting VM...
There was an error while executing `VBoxManage`, a CLI used by Vagrant
for controlling VirtualBox. The command and stderr is shown below.
Command: ["export", "64precise6", "--output", "/Users/earthmant/.vagrant.d/tmp/1417878317/box.ovf"]
Stderr: 0%...
Progress state: VBOX_E_FILE_ERROR
VBoxManage: error: Appliance write failed
VBoxManage: error: File not accessible or erroneous file contents
VBoxManage: error: Details: code VBOX_E_FILE_ERROR (0x80bb0004), component Appliance, interface IAppliance
VBoxManage: error: Context: "int handleExportAppliance(HandlerArg*)" at line 1121 of file VBoxManageAppliance.cpp
I noticed that a lot of people explicitly state that when you create the VM in VirtualBox, you should use the vmdk file format for the disk. I had used qcow. When I rebuilt the VM with vmdk, vagrant package succeeded.

Resources