Vagrant keeps trying to use use AWS plugin. How to stop? - vagrant

I'm just trying to vagrant up a standard Ubuntu image for the first time. My company has set up Vagrant on my laptop already and installed some plugins for AWS. When I try to run vagrant up on my personal Ubuntu image, with a separate Vagrantfile, I get the following error:
There are errors in the configuration of this machine. Please fix
the following errors and try again:
AWS Provider:
* An access key ID must be specified via "access_key_id"
* A secret access key is required via "secret_access_key"
* An AMI must be configured via "ami" (region: #{region})
I'm not trying to connect to AWS. I'm just trying to set up my first personal image on my laptop.

Make sure you actually have VirtualBox installed. I witnessed this error message today and it was because I had the vagrant-aws plugin installed but not VirtualBox. Installing VirtualBox was all that was needed to fix the problem.
If for some reason that still fails, then, per the OP's comment above, try using vagrant up's --provider option:
vagrant up --provider virtualbox

By default Vagrant will go through all of the config.vm.provider and will choose the first usage provider, so you should add virtualbox before aws:
config.vm.provider "virtualbox" do |v|
v.customize ['modifyvm', :id, '--natdnshostresolver1', 'on']
v.memory = 4096
v.cpus = 2
end
or choose different provider manually either by --provider as already mentioned, or VAGRANT_DEFAULT_PROVIDER variable:
VAGRANT_DEFAULT_PROVIDER=virtualbox vagrant up
or use config.vm.provider with no configuration in order to set the order in your Vagrantfile like:
Vagrant.configure("2") do |config|
# ... other config up here
# Prefer VirtualBox Fusion before VirtualBox
config.vm.provider "virtualbox"
config.vm.provider "aws"
end
See: Basic provider usage at vagrantup.com
If you need to use AWS provider, these error means you need to set-up the right credentials by using aws configure command, so ~/.aws/credentials can be created with your aws_access_key_id and aws_secret_access_key values. For AMI configuration, check README file of the plugin (basically you need to add aws.ami into your Vagrant file).

Related

How do you set the VM name via Vagrant?

I've set up 4 VMs in Vagrant and now trying to set the name of a VM in Vagrant as I don't just want to ssh into the default VM.
I can't find any docs on the vagrant website but found this:
How to change Vagrant 'default' machine name?
However, when I try:
config.vm.define "foohost"
and do a vagrant up I get:
There are errors in the configuration of this machine. Please fix
the following errors and try again:
vm:
* The following settings shouldn't exist: define
I suspect you actually wrote
config.vm.define = "foohost"
rather than
config.vm.define "foohost"
as that would explain the error message. (Best to show several lines of actual source if you can.)
as I don't just want to ssh into the default VM.
so when you use multiple VM, you can tell vagrant which VM you want to ssh by default, using the following
config.vm.define "foohost", primary: true do |foohost|
...
end
then when you run vagrant ssh you will ssh by default in this VM.
To ssh into the other MV, you will need to specify the VM name

How to up Vagrant with hashicorp/precise64 box?

I started learning Vagrant and I'm trying to up vagrant machine with hashicorp/precise64 box. I've installed VirtualBox 5.1 on Gentoo and I emerged Vagrant from Gentoo repository. I executed following command in terminal:
pecan#tux ~/vagrant_getting_started $ vagrant box add hashicorp/precise64
==> box: Loading metadata for box 'hashicorp/precise64'
box: URL: https://vagrantcloud.com/hashicorp/precise64
This box can work with multiple providers! The providers that it
can work with are listed below. Please review the list and choose
the provider you will be working with.
1) hyperv
2) virtualbox
3) vmware_fusion
Enter your choice: 2
==> box: Adding box 'hashicorp/precise64' (v1.1.0) for provider: virtualbox
box: Downloading: https://vagrantcloud.com/hashicorp/boxes/precise64/versions/1.1.0/providers/virtualbox.box
==> box: Successfully added box 'hashicorp/precise64' (v1.1.0) for 'virtualbox'!
pecan#tux ~/vagrant_getting_started $ nano Vagrantfile
pecan#tux ~/vagrant_getting_started $ vagrant up
No usable default provider could be found for your system.
Vagrant relies on interactions with 3rd party systems, known as
"providers", to provide Vagrant with resources to run development
environments. Examples are VirtualBox, VMware, Hyper-V.
The easiest solution to this message is to install VirtualBox, which
is available for free on all major platforms.
If you believe you already have a provider available, make sure it
is properly installed and configured. You can see more details about
why a particular provider isn't working by forcing usage with
`vagrant up --provider=PROVIDER`, which should give you a more specific
error message for that particular provider.
and I got above error when I tried to up Vagrant machine.
Vagrantfile content:
# -*- 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://vagrantcloud.com/search.
config.vm.box = "base"
# 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: 8080
# 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 "../data", "/vagrant_data"
# 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.
# 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
Vagrant.configure("2") do |config|
config.vm.box = "hashicorp/precise64"
end
end
vagrant up --provider=virtualbox command returns the below error:
pecan#tux ~/vagrant_getting_started $ vagrant up --provider=virtualbox
The provider 'virtualbox' that was requested to back the machine
'default' is reporting that it isn't usable on this system. The
reason is shown below:
Vagrant could not detect VirtualBox! Make sure VirtualBox is properly installed.
Vagrant uses the `VBoxManage` binary that ships with VirtualBox, and requires
this to be available on the PATH. If VirtualBox is installed, please find the
`VBoxManage` binary and add it to the PATH environmental variable.
I'm counting for help!
The Vagrantfile is wrong, it does not contain the correct box information
You can remove the whole folder all together and start with vagrant init hashicorp/precise64 which will create a correct Vagrantfile, then you can run vagrant up (virtual box should be the default provider if not run vagrant up --provider virtualbox)
Fix the Vagrantfile and replace
config.vm.box = "base"
with
config.vm.box = "hashicorp/precise64"
Then you can run vagrant up and it will work.

Is "vagrant up" possible from different local directories with custom URLs?

I have two directories under /var/www/html, named vlp1 and vlp2 with Vagrant setup. If I run vagrant up separately in these folders the default local URL is vagrant.local for both. But vagrant.local/ always loads site from vlp1 folder.
As it should be, vagrant global-status shows that I have two virtual machines running under these directories. I require to run both sites side by side and to do this the only option I see is to have separate URLs. I believe there is a way to assign different URLs to different sites but don't have any idea how!
What I need to do to accomplish the above so that my sites run like local.vlp1.com and local.vlp2.com or may be like vagrant.vlp1 and vagrant.vlp2?
According to project instructions I have to keep two sites completely separated in two folders and have to use separate Vagrantfiles.
OS: Ubuntu 14.04 64 bit
Installed VitualBox version: 5.1
Installed Vagrant version: 1:1.9.4
Thank you!
UPDATE
Went through the following steps as advised by Henri:
Step 1:
$ vagrant global-status
Output:
id name provider state directory
------------------------------------------------------------------------
eb9b569 default virtualbox running /var/www/html/vlp1
190608c default virtualbox running /var/www/html/vlp2
Step 2: Did a graceful shutdown on vlp2
$ vagrant halt 190608c
Step 3: Output of vagrant global-status now is
id name provider state directory
-------------------------------------------------------------------------
eb9b569 default virtualbox running /var/www/html/vlp1
190608c default virtualbox poweroff /var/www/html/vlp2
Step 4:
$ sudo gedit /var/www/html/vlp2/Vagrantfile
if CONF['ip'] == "dhcp"
config.vm.network :private_network, type: "dhcp", hostsupdater: "skip"
else
config.vm.network :private_network, ip: "192.168.2.5"
end
Step 5: Re up'd vlp2 machine
$ vagrant up 190608c
Step 6:
$ vagrant global-status now shows both machine are back to running state again.
id name provider state directory
------------------------------------------------------------------------
eb9b569 default virtualbox running /var/www/html/vlp1
190608c default virtualbox running /var/www/html/vlp2
Step 7:
In /etc/hosts added following entry
192.168.2.5 vagrant.vlp2
Finally I tried vagrant.vlp2/ in browser but ended up with the following message:
This site can’t be reached
http://vagrant.vlp2/ is unreachable.
As I understand you're using multiple VM so the easiest in this case is to assign each of the VM a static IP (that must be different) so you do so in Vagrantfile
Vagrant.configure("2") do |config|
...
config.vm.network "private_network", ip: "192.168.10.x"
...
end
and you use another IP for the second VM
Vagrant.configure("2") do |config|
...
config.vm.network "private_network", ip: "192.168.20.y"
...
end
and then you update your /etc/hosts file with the information
192.168.10.x vagrant.vlp1
192.168.20.y vagrant.vlp2

Vagrant cannot vagrant up the box packaged from ubuntu xenial64 16.04

I have a custom vagrant box based on the offcial box ubuntu 16.04.
I simplly run like this to get the packaged box.
vagrant init ubuntu/xenial64; vagrant up --provider virtualbox
vagrant up
vagrant ssh # enter the virtual machine and do some custom change on it
vagrant halt
vagrant package --vagrantfile Vagrantfile --output custom_ubuntu1604.box
and then i copy the file custom_ubuntu1604.box to another directory, i use the box like this:
vagrant box add ubuntu1604base custom_ubuntu1604.box
vagrant init ubuntu1604base
vagrant up # at this point the machine will be stopped at "Started Journal Servie"
my new virtualbox machine base on the new packaged box will stop at:
the screenshot
And finally it timed out:
Timed out while waiting for the machine to boot. This means that
Vagrant was unable to communicate with the guest machine within the
configured ("config.vm.boot_timeout" value) time period.
If you look above, you should be able to see the error(s) that Vagrant
had when attempting to connect to the machine. These errors are
usually good hints as to what may be wrong.
If you're using a custom box, make sure that networking is properly
working and you're able to connect to the machine. It is a common
problem that networking isn't setup properly in these boxes. Verify
that authentication configurations are also setup properly, as well.
If the box appears to be booting properly, you may want to increase
the timeout ("config.vm.boot_timeout") value.
Try to set config.vm.boot_timeout in Vagrantfile more than default e.x.600. From my experience I found out it take a long time at the first time to connecting guest machine.
For example
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/xenial64"
config.vm.provider "virtualbox"
config.vm.boot_timeout = 600
end

How to use packer with box file?

I have a vagrantfile using a box on top of virtualbox with a provision script.
Now I am trying to use packer to output a box already after provision.
However I cannot find a builder to use the ".box" file I already have. What am I doing wrong?
I just got a solution to this tiny little problem (convert a vagrant .box file to .ova for use by packer):
Create a vm using the .box file as a base. I use this Vagrantfile, with box opscode-centos-7.0:
$provisioning_script = <<PROVISIONING_SCRIPT
adduser packer
echo "packer" | passwd packer --stdin
echo "packer ALL=(ALL:ALL) NOPASSWD: ALL" > /etc/sudoers.d/packer
PROVISIONING_SCRIPT
Vagrant.configure(2) do |config|
config.vm.box = "opscode-centos-7.0"
config.ssh.insert_key = false
config.vm.provider "virtualbox" do |v|
v.name = "packer-base"
end
config.vm.provision :shell, inline: $provisioning_script
end
run vagrant up
run vagrant halt
run vboxmanage export --ovf20 -o packer-base.ova packer-base
run vagrant destroy
This also creates the packer user with a default password so that packer can easily connect to the instance to do stuff. Also note the insert_key parameter that will prevent replacing the vagrant default insecure key with a secure one and allow subsequent vagrant setups to properly connect via SSH to the new images (after packer is done).
Packer out-of-the-box doesn't support using Vagrant boxes as input (yet).
But there is a custom plugin, see this comment.
If you want to build a vagrant box that runs with provider virtualbox, have a look here.
However, it takes an iso or ovf as input, not a vagrant box.
Have a look at these templates to get you started using the virtualbox builder with packer.
Make sure your run the post-processor to convert the virtualbox vm into a vagrant box.

Resources