How vagrantfile use dowloaded vagrant box - vagrant

After I download centos6.6 vagrant box from official site of vagrant . but how to use them ,in the Vagrantfile ?

I get it aha,
use the
on windows :
config.vm.box_url = "file:///path-to-vbox/package.box"
on linux :
config.vm.box_url = "/path-to-vbox/package.box"
After I used this way , but the best way is :
vagrant box add titile pasth-to-vbox

To add a box you have downloaded in vagrant use this command :
vagrant box add {title} {url or path to the .box}
You can list the box you installed with this command:
vagrant box list
# example output :
hashicorp/precise32 (virtualbox, 1.0.0)
mitchellh/boot2docker (virtualbox, 1.2.0)
To use a box, the simpliest way is to put this parameter in your Vagrantfile:
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
config.vm.box = "mitchellh/boot2docker"
end
Then in this folder run the command :
vagrant up

Related

Automatically downloading & installing cookbooks on a vagrant box

I'm trying to create a Vagrant box that'll install some services when I run vagrant up.
For that purpose, I'm making use of these services:
Oracle VirtualBox
Chef Solo provisioner
Berkshelf
Vagrant Berkshelf Plugin
I'm using Berkshelf in order to handle cookbook dependencies.
The issues arise with certain cookbooks, which simply won't install.
Currently I'm trying to install nginx, from the cookbook I found on Chef Supermarket - nginx cookbook.
Berksfile:
source "https://supermarket.chef.io"
cookbook "nginx"
Vagrantfile:
Vagrant.configure("2") do |config|
config.vm.box = "CentOS-6.5-minimal-0.1.1"
config.vm.network "private_network", ip: "192.168.33.10"
config.vm.hostname = "vagrant"
config.vm.synced_folder ".", "/var/www", :mount_options => ["dmode=777", "fmode=666"]
config.berkshelf.enabled = true
config.vm.provision :chef_solo do |chef|
chef.cookbooks_path = ["cookbooks"]
chef.add_recipe "nginx"
end
end
I tried running vagrant provision with a combination of vagrant reload and shutting the box down and running vagrant up
The closest I've gotten to determining the cause of the problem is this stacktrace, I've gotten when running vagrant provision.
Any help for resolving this will be much appreciated.
The key issue here is you are using the Chef version that ships in Hashcorp's default boxes (Starting Chef Client, version 11.8.2). This version is too old to use the current nginx cookbook. You probably want to use the bento boxes which don't include a baked in version of Chef and then install it via Vagrant's omnibus support.

Building a Vagrantfile with Chef provisioning not working

I'm trying to follow the following text tutorial and my setup breaks at the point where he types "bundle install", my setup did not install bundle so clearly there's something wrong with my Chef stuff - https://gorails.com/guides/using-vagrant-for-rails-development
edit: Why was this question downvoted? Did I fail to provide some background?
I ran the first two commands.
vagrant plugin install vagrant-vbguest
vagrant plugin install vagrant-librarian-chef-nochef
I created a folder and made a Cheffile and Vagrantfile like so:
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# Use Ubuntu 14.04 Trusty Tahr 64-bit as our operating system
config.vm.box = "ubuntu/trusty64"
# Configurate the virtual machine to use 2GB of RAM
config.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", :id, "--memory", "2048"]
end
# Forward the Rails server default port to the host
config.vm.network :forwarded_port, guest: 3000, host: 3000
# Use Chef Solo to provision our virtual machine
config.vm.provision :chef_solo do |chef|
chef.cookbooks_path = "cookbooks"
chef.add_recipe "apt"
chef.add_recipe "nodejs"
chef.add_recipe "ruby_build"
chef.add_recipe "rbenv::vagrant"
chef.add_recipe "rbenv::user"
chef.add_recipe "vim"
chef.add_recipe "mysql::server"
chef.add_recipe "mysql::client"
# Install Ruby 2.2.1 and Bundler
# Set an empty root password for MySQL to make things simple
chef.json = {
rbenv: {
user_installs: [{
user: 'vagrant',
rubies: ["2.2.1"],
global: "2.2.1",
gems: {
"2.2.1" => [
{ name: "bundler" }
]
}
}]
},
mysql: {
server_root_password: ''
}
}
end
end
Cheffile
site "http://community.opscode.com/api/v1"
cookbook 'apt'
cookbook 'build-essential'
cookbook 'mysql', '5.5.3'
cookbook 'ruby_build'
cookbook 'nodejs'
cookbook 'rbenv', git: 'https://github.com/aminin/chef-rbenv'
cookbook 'vim'
I have spent 3 days so far fiddling with this all day and night and I cannot get it to work. I launch my vagrant box and bundler is not installed so I can't bundle install.
Clearly the chef.json is not working. I have tried pouring over the error output, I've been googling and have hundreds of tabs open, at this point I am completely lost.
In my chef.json, how does that work? How do I begin to find out how to craft my own chef.json? I don't understand it, how do I know to write user_installs for example?
Is there a difference between the following:
a) config.vm.provision :chef_solo do |chef|
b) config.vm.provision "chef solo" do |chef|
I can't even Google anything related to Chef and cookbooks because I get cooking results, you know, for FOOD.
Ahoy. There are a lot of questions up there.. so I'll try to go 1 at a time
*) Locally, did you install chef-client or chef dk?
Chefclient will not have bundler, where are chefdk does. It's also generally a smoother experience.
If you are using chef-client. You'll have to get bundler gem install bundler
If you are using chefdk. You'll either add chefdk ruby to your path, use temporary environment settings (eval "$(chef shell-init bash)") or just use chef exec bundle ...
*) Semi unrelated. But the comments on that blog go way back to 10+ months ago. I suggest you take a look at the https://learn.chef.io/index.html for the latest tutorials
*) chef_solo and 'chef solo' are different things. :chef_solo is a symbol. Think of it as thing that has special meaning within vagrant language. chef solo would have no meaning - a) it has a space in it, so it would be two different things - either variables (undefined in your example) or "chef solo" a string, which would have no meaning to the provisioner.
*) for googling chef related results, I suggest using http://docs.chef.io or including the name of the tool 'chef vagrant nil error'
Finally, applause for going off and learning this toolset. It's awesome, but a whole new universe.

Vagrant Berkshelf could not find the 'berks' executable in your PATH. When running 'vagrant up'

$ vagrant up
Bringing machine 'district' up with 'virtualbox' provider...
Vagrant Berkshelf could not find the 'berks' executable in your PATH.
Please download and install the latest version of the ChefDK from:
https://downloads.getchef.com/chef-dk
and follow the installation instructions. Do not forget to add the ChefDK to
your PATH.
I downloaded the latest version of ChefDK as instructed.
How would I add the path to Berkshelf in the vagrant file?
Here is the my current Vgrantfile:
$ cat Vagrantfile
# vi: set ft=ruby :
Vagrant.configure('2') do |config|
config.vm.define 'district' do |app|
app.vm.box = 'ubuntu/trusty64'
app.vm.provider 'virtualbox' do |v|
v.memory = 1024
v.name = 'district'
end
app.ssh.forward_agent = true
app.vm.network :forwarded_port, guest: 4567, host: 4567
app.vm.synced_folder './', '/home/vagrant/WhatsMyDistrict'
app.berkshelf.enabled = true
app.vm.provision :chef_solo do |chef|
chef.log_level = :debug
chef.custom_config_path = 'chef_solo.config'
chef.run_list = ['whatsmydistrict::default']
end
end
end
Make sure you've added /opt/chefdk/bin to your $PATH.
It's recommended to have it prior to any ruby path locations - prepending is the easiest way to ensure this.
export PATH=/opt/chefdk/bin:$PATH
For Windows users ChefDK is installed in C:\opscode\chefdk\bin as explained here.
So you have to write this command line instead :
export PATH=/c/opscode/chefdk/bin:$PATH.
You can also follow these steps adding the path C:\opscode\chefdk\bin. You may have to restart your computer to apply the changes.

Provider docker not found - Vagrant

Whenever I run vagrant up --provider=docker, I get this error message.
The provider 'docker' could not be found, but was requested to
back the machine 'default'.
But, when i run Docker himself, without vagrant everything works fine.
I'm on Linux Mint Rebecca. All is updated.
Vagrantfile
# -*- 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.network :private_network, ip: "192.168.33.10"
config.vm.synced_folder "./", "/vagrant_data"
config.vm.provider "docker" do |d|
d.image = "ubuntu"
end
end
After a completely reinstall (vagrant and docker), it works. :)

Puppet module install error - Directory /home/vagrant/.puppet/modules does not exist

I've got puppet working (with Vagrant) with a few of my own simple modules but i'm running into difficulty when trying to install modules from puppet forge.
VagrantFile:
Vagrant::Config.run do |config|
config.vm.box = "hashicorp/precise64"
config.vm.forward_port 80, 3000
config.vm.provision :puppet do |puppet|
puppet.module_path = "modules"
end
end
From inside my Virtual machine I am running:
puppet module install akandels-phpunit
I get the following error:
Error: Could not install module 'akandels-phpunit' (latest)
Directory /home/vagrant/.puppet/modules does not exist
I've seen one answer to Vagrant+Puppet puppet.module_path not working but it's not very clear.
I am using the basebox hashicorp/precise64 which is working fine with my own puppet modules.
What could be the problem here? Am I using puppet wrong? Thanks

Resources