Vagrant with docker provisioning - vagrant

I am new to docker and vagrant. I installed vmbox and vagrant in my ubuntu 14.04 machine.
I did "git clone https://github.com/dotcloud/docker.git" to get the docker repository. I have also added precise64 from vagrant successfully.
From docker directory i tried "vagrant up". But it told me to do "vagrant init" first. So I did "vagrant init precise64". After doing "vagrant ssh" there is no docker inside the precise64 vm. How can I make sure that docker is installed already in precise64 on startup?
PS: vagrantfile is not allowing " config.vm.provision "docker" "

The following Vagrantfile will get you a VM with docker ready to go:
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
config.vm.box = "phusion/ubuntu-14.04-amd64"
config.vm.hostname = "dockerhost"
config.vm.provision "shell", inline: <<-SCRIPT
curl -sL https://get.docker.io/ | sh
curl -sL https://raw.githubusercontent.com/dotcloud/docker/master/contrib/completion/bash/docker > /etc/bash_completion.d/docker
adduser vagrant docker
SCRIPT
end
EDIT :
Even easier, you can now use Docker Toolbox to get up and running.

You might be using old version of vagrant.
config.vm.provision "docker" work only with vagrant 1.6.5 .
Try upgrading your vagrant to 1.6.5. It will resolve the issue.

Upgrading the Vagrant to 1.6.5 resolves the issue.

Related

apt-get command not found in Vagrant/Window

When I run vagran up command, I get the error apt-get command not found in vagrant, my pc is using window-10.
Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
# VM Box
config.vm.box = "centos-7"
config.vm.network "private_network", ip: "192.168.33.100"
config.vm.provider "virtualbox" do |vb|
vb.memory = 2048
vb.cpus = 4
end
config.vm.provision "shell", path: "bootstrap.sh"
end
bootstrap.sh
sudo apt-get update
sudo apt-get apgrate
sudo apt-get install -y git
you're using a centos box
config.vm.box = "centos-7"
so you should use the yum package manager, apt is used for ubuntu family and is not compatible with the other os family (Debian vs Fedora)
To install git on centos replace your bootstrap script by
yum update
yum install -y git
Have you tried using yum and trying $ vagrant box update? Also, you can get more in depth logs by using $ vagrant up --debug or if you would like to save it to a file $ vagrant up --debug &> vagrant.log. I always recommend doing some VM house keeping as well by making sure all VMs are stopped then run $ vagrant reload --provision on the VM having the issues. As always, the best part of using Vagrant is the ability to wipe it and start over again.

make it so vagrant doesn't run apt-get update automatically

When I do vagrant up on a new machine it tries do a sudo apt-get update before it runs of the provisioning lines. It appears that the process still exists however.
My Vagrantfile:
Vagrant.configure("2") do |config|
config.vm.box = "scotch/box"
config.vm.box_version = "1.5.0"
config.vm.box_check_update = false
config.vm.network "private_network", ip: "192.168.33.10"
config.vm.hostname = "vagrant"
config.vm.provision "shell", inline: <<-SHELL
apt-get -y install pdftk
SHELL
end
The problem is that some of the APT repos are returning 404's. This is causing output to stderr which appears to be preventing the shell provisioner winds up not running. Doing vagrant halt and then vagrant up a second time seems to do the trick but I'd rather not have to do 3x commands when 1x could be sufficient.
Anyway ideas how to disable this behavior?
Here's the output when I do vagrant up after doing vagrant destroy:
https://pastebin.com/4Hh49J7c
The errors in the logs are due to the vagrant vbguest plugin. This plugin will need to install the guest additions package for virtualbox matching your version and to do so some apt-get update are run.
You can disable this if this is causing issues during the creation of your VM
Vagrant.configure("2") do |config|
config.vbguest.auto_update = false
end
If you later want to align the version between virtualbox and the guest addition (this is recommended) you can run the following command
$ vagrant vbguest install

Provision script in Laravel/Homestead

I wonder how I can include a provision script in Laravel/Homestead that should execute each time the Homestead VM is up.
As a hint, I used to work with Vagrant in following way,
config.vm.provision :shell, path: "bootstrap.sh"
where the bootstrap.sh file is my provision script.
You can always manually force a provision with either vagrant provision or vagrant reload --provision.
To make a every vagrant up automatically call the provisioner then simply define it in your Vagrantfile like so:
Vagrant.configure("2") do |config|
config.vm.provision :shell, path: "bootstrap.sh",
run: "always"
end
You can then choose to not run the provisioner by using the vagrant up --no-provision.
The Vagrant docs on this go into a little more detail about what else you can do with provisioners.

Vagrant can't run ansible when provisioning

I have created a Vagrantfile to provision a new box using Ansible. Both the Vagrantfile and the Ansible playbooks are ones I've used before, prior to an upgrade to OS X Yosemite. I can successfully vagrant up but when I try to vagrant provision I get the following error:
➜ NNL vagrant provision
==> default: Running provisioner: ansible...
The executable 'ansible-playbook' Vagrant is trying to run was not
found in the PATH variable. This is an error. Please verify
this software is installed and on the path.
Update 2: Here's the verbose (vvvv) output for the command above:
➜ ta vagrant provision
==> default: Running provisioner: ansible...
ANSIBLE_FORCE_COLOR=true ANSIBLE_HOST_KEY_CHECKING=false PYTHONUNBUFFERED=1 ANSIBLE_SSH_ARGS='-o
ForwardAgent=yes -o ControlMaster=auto -o ControlPersist=60s' ansible-playbook --private-
key=/Users/mike/.vagrant.d/insecure_private_key --user=vagrant --connection=ssh --
limit='default' --inventory-file=/Users/mike/Desktop/ta/.vagrant/provisioners/ansible/inventory
-vvvv vagrant.yml
The executable 'ansible-playbook' Vagrant is trying to run was not
found in the PATH variable. This is an error. Please verify
this software is installed and on the path.
I have already updated ansible and vagrant as part of my troubleshooting:
➜ NNL ansible --version
ansible 1.8.1
configured module search path = None
➜ NNL ansible-playbook --version
ansible-playbook 1.8.1
configured module search path = None
➜ NNL vagrant --version
Vagrant 1.6.5
Ansible is definitely installed and /usr/local/bin is on the PATH environment variable.
➜ NNL which ansible
/usr/local/bin/ansible
➜ NNL echo $PATH
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
Update 1: Here's my Vagrantfile, I've cut it back to the bare minimum:
# -*- 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.box = "precise64"
config.vm.hostname = "NNL"
config.vm.box_url = "http://files.vagrantup.com/precise64.box"
config.vm.network :forwarded_port, guest: 80, host: 8080
config.vm.network :forwarded_port, guest: 3000, host: 3000
config.vm.network :forwarded_port, guest: 9200, host: 9200
config.ssh.forward_agent = true
config.vm.provision "ansible" do |ansible|
ansible.playbook = "vagrant.yml"
end
end
My other thought was that I'm using zsh and perhaps vagrant is executing commands through bash or some other shell, so I also tried to add a .bashrc file to ensure that /usr/local/bin was on the path for that shell too. It appears to be, but I still get the same error:
➜ NNL bash
bash-3.2$ echo $PATH
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
bash-3.2$ which ansible
/usr/local/bin/ansible
I'm at a loss now as to how to proceed. As a footnote, my other vagrant boxes which I created successfully under Mavericks also now fail with the same error when I try to re-provision them.
I haven't used Yosemite so far, but if I understand well your same setup worked fine on a previous version of OS X.
First to collect a bit more information: when the vagrant box is up, could you please re-run the ansible-playbook command that is displayed in vagrant logs, but directly from a shell (bash or zsh should not matter):
ANSIBLE_FORCE_COLOR=true ANSIBLE_HOST_KEY_CHECKING=false PYTHONUNBUFFERED=1 ANSIBLE_SSH_ARGS='-o ForwardAgent=yes -o ControlMaster=auto -o ControlPersist=60s' ansible-playbook --private-key=/Users/mike/.vagrant.d/insecure_private_key --user=vagrant --connection=ssh --limit='default' --inventory-file=/Users/mike/Desktop/ta/.vagrant/provisioners/ansible/inventory -vvvv vagrant.yml
What is the result?
If it works fine (which I expect, based on your problem description), then we are sure that we must chase something in Vagrant internals (in combination with Yosemite environment maybe).
So finally I fixed the problem. Turns out an iTerm upgrade (to iTerm 2, June 2014) was needed. I don't fully understand the ins and outs of what was causing the problem but there's more information here: https://github.com/Homebrew/homebrew/issues/29843
There is no need to install Ansible inside the Vagrant box. Ansible is agentless. Ansible uses SSH (or other protocols) to connect to other hosts. So there is no need to have Ansible executable inside the guest. You just need to have Ansible installed on the host running vagrant.

Does vagrant automatically install puppet?

I have this in my Vagrantfile:
Vagrant.configure("2") do |config|
config.vm.provision "puppet"
end
Yet, when I run puppet --version I get :
[vagrant#vagrant-centos65 ~]$ puppet --version
-bash: puppet: command not found
Do I need to manually install puppet?
No, (at the moment) Vagrant doesn't install it automatically.
So you either need to use a basebox which already has it installed (Puppet Labs provides boxes too), or you need to install it yourself. Probably the easiest way to install is to use shell provisioner before the puppet provisioner(s).
In response to #tmatilai, I created this simple set up:
Vagrantfile:
Vagrant.configure(2) do |config|
config.vm.box = "centos6.5_64"
config.vm.provision "shell", path: "manifests/puppet.sh"
config.vm.provision "puppet"
end
manifest/puppet.sh:
echo "Adding puppet repo"
sudo rpm -ivh https://yum.puppetlabs.com/el/6/products/x86_64/puppetlabs-release-6-7.noarch.rpm
echo "installing puppet"
sudo yum install puppet -y
echo "ensure puppet service is running"
sudo puppet resource service puppet ensure=running enable=true
#echo "ensure puppet service is running"
#sudo puppet resource service puppetmaster ensure=running enable=true
echo "ensure puppet service is running for standalone install"
sudo puppet resource cron puppet-apply ensure=present user=root minute=30 command='/usr/bin/puppet apply $(puppet apply --configprint manifest)'
[vagrant#vagrant-centos65 home]$ puppet --version
3.4.2
If you want to use a plugin, I made one that will automatically install Puppet from a version given in the Vagrantfile:
Vagrant.configure("2") do |config|
config.puppet_install.puppet_version = :latest
end
This will also do a few cool tricks like make sure the puppet version you specify is a valid version and the like, full details here: https://github.com/petems/vagrant-puppet-install/
Yes. I'm not sure what the state of Vagrant was at the time of some of these other answers, but these days puppet does not have to be installed via a shell provisioner, as Vagrant has a support puppet provisioner built right in.
At the most basic level, you can make sure puppet is supported on your box by adding provision "puppet" or provision "puppet_server" to your `Vagrantfile. For example:
#open config block (already present in your templated Vagrantfile)
Vagrant.configure(2) do |config|
#...[snip]... other config.vm settings. Ex...
# Ubuntu 14.04 LTS version
#config.vm.box = "ubuntu/trusty64"
# Make puppet avail inside machine
config.vm.provision "puppet"
#close out Vagrant configuration for this instance
end
using puppet sets up puppet for local puppet apply (uses local manifests for configuring your machine), whereas using puppet_server hooks you up to a puppet master, and allows you to provision your vagrant box using a puppet server (a puppet master agent).
As a few other people have already answered, there is no 'standard' that ensures a vagrant box comes pre-installed with Puppet.
By design, a vagrant box could have 'anything' pre-installed on it. Or it could just as easily have 'nothing' at all pre-installed. It all depends on who created it and what they included in the process of setting up the box.
If you find that your machine doesn't have Puppet pre-installed on it, you could also use one of the scripts that Mitchell Hashimoto has put together. See the following project on GitHub for details...
https://github.com/hashicorp/puppet-bootstrap
At this point of time of writing, Vagrant does pre-installs puppet service. I ssh-ed into guest machine (used the box 'ubuntu/trusty64') and got following result :
vagrant#vagrant-ubuntu-trusty-64:~$ puppet --version
3.4.3
As stated by others it depends on the box. For instance ubuntu/trusty64 comes with puppet pre-installed whereas ubuntu/xenial64 does not.
So to fix this for Ubuntu ubuntu/xenial64 adding an inline shell provisioner before the puppet provisioner is enough:
config.vm.box = "ubuntu/xenial64"
config.vm.provision :shell, :inline => 'apt-get -y update; apt-get -y install puppet'
config.vm.provision :puppet do |puppet|
# ...
As of June 16 2016 Vagrant does NOT install puppet within the client VM as far as I can tell. I believe like it's sister project "packer" it expects you to do so explicitly. See: https://www.packer.io/docs/provisioners/puppet-masterless.html
Note: Puppet will not be installed automatically by this provisioner.
This provisioner expects that Puppet is already installed on the
machine. It is common practice to use the shell provisioner before the
Puppet provisioner to do this.
this worked for me:
put this inside your Vagrantfile - before your provisioning
$script = <<SCRIPT
echo I am installing puppet on guest
sudo apt-get install -yq puppet=*
SCRIPT
Vagrant.configure("2") do |config|
config.vm.provision "shell", inline: $script
end
This should install a puppet agent on the guest before you do other provisioning

Resources