Vagrant workflow - vagrant

Hi i was trying to understand what exactly is done when running
vagrant up
my reason for that is that in my case we need to install a lot of utilities.
i.e Version control tools, build tools, ide, etc...
which takes a lot of time.
so actually i wanted a 'box' with all those tools.
After i have clean environment and got all tools, i would like to make CI for our product.
If i will reinstall all utilities it should take a lot of time. so what i am actually need is just installing and testing our product.
How should i handle that ??
create my own box? does the command reinstall all utilities when we make CI ??
what i actually need are 2 processes :
1.installing utilities for my vm. (once a month)
2.test our product (each commit\push to version control)
how can i achieve that ?

For the first time, vagrant up will create a new VM for you, pulling the box image if needed, and it will provision it with what you configured in the Vagrantfile. In the provision configuration, you can tell Chef or Puppet to install all the utilities and tools that you need.
When you suspend or halt the VM, the next time you do a vagrant up it will only bring that VM back up. It will not install or try to provision it again.
You can force it with vagrant up --provision or just vagrant provision.
This usually works well in a development environment.
In a CI environment, it may not be possible to have the VM already provision, forcing you to run the provisioning step every time. You can achieve what you need packaging your own box with the tools already installed, essentially creating a golden or base image.
Just be extra careful so that the CI environment don't differ for what you have in production.

All depend on the setting in Vagrantfile
you have modules folder to put all puppet modules, manifests folder with site.pp and Vagrantfile as below under same place.
Give you a sample of Vagrantfile I used mostly.
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "precise64"
config.vm.box_url = "https://cloud-images.ubuntu.com/vagrant/precise/current/precise-server-cloudimg-amd64-vagrant-disk1.box "
config.vm.provision :puppet do |puppet|
puppet.module_path = "modules"
puppet.manifests_path = "manifests"
puppet.manifest_file = "site.pp"
end
config.vm.define :www do |config|
config.vm.host_name = "www.example.com"
config.vm.network :private_network, ip: "192.168.1.2"
end
config.vm.define :db1 do |config|
config.vm.host_name = "db1.example.com"
config.vm.network :private_network, ip: "192.168.1.4"
end
end
So after run vagrant up www or vagrant up db1 it will start the box with puppet apply directly. You can understand this way as puppet masterless
Vagrant just make the box up running from linux image defined in config.vm.box_url as a simple fresh linux box, and mount your local folder to new box's /vagrant folder, then hand over to puppet. How the server to be provisioned, will be depended on site.pp (define applications on each node) and puppet modules. The command is similar as
puppet apply --modulepath /vagrant/module /vagrant/manifests/site.pp
So if your puppet modules are fine, your new box will automatically have all utilities and products installed. Then you run vagrant ssh www or vagrant ssh db1, you can login it and start working.
You can put your local folder with moduels, manifests folders and Vagrantfile to version control (such as git). So developers can clone the git repository to their own computer easily.

Related

Default shared folder in vagrant not visible

I have a problem with synced folder in Vagrant. My config is really simple:
Vagrant.configure(2) do |config|
config.vm.box = "ubuntu/xenial64"
config.vm.network :forwarded_port, guest: 80, host: 8080
config.vm.synced_folder ".", "/vagrant"
end
Vagrant usually creates /vagrant folder automatically on start - this time it did not happen so I've done it manually.
But when I create a file in my host system - it's not visible in guest. Any ideas why?
I've succesfully created a similar configuration with:
config.vm.box = "hashicorp/precise64"
but it's a little bit outdated and I want to use Ubuntu 16.04.
Is it a problem with my config, vagrant box, or something else?
You could try: Make sure you have the latest version of Vagrant and VB. Restart your computer (I know, but it sometimes does help in these cases). Try again in a new directory (or vagrant destroy if you want to start fresh and don't need any old content), i.e., make sure the old .vagrant directory isn't there.
vagrant up or vagrant reload and check again.
Assuming you are using VirtualBox, make sure you don't have any "Guest Additions" issues. You could try https://github.com/dotless-de/vagrant-vbguest
If it still doesn't work, check the --debug output again as #frédéric-henri mentioned -- look for all mentions of your share name. Also "/vagrant" isn't always the default, it depends on the box. Sometimes it's "/vagrant_data" or others, but if you specify "/vagrant" in the config -- that should work.

Is it possible to provision vagrant boxes from puppet modules located outside of the vagrant folder?

I have a production server architecture that is quite complex that involves several types and tiers of servers including: Web, Varnish, HAProxy, ELK, Database, Sensu, etc. The production architecture is provisioned with puppet masters and the puppet code for the masters is provisioned with Git through many, submodules.
I want to connect these Git repos to VM's locally to further develop pieces of the puppet architecture. However each Vagrant VM requires a complete self contained copy of all of the Git repos in order to stand up just one VM. This seems like a very inefficient use of drive space for local development on what will be potentially a dozen different types of servers.
Is there a way to point all of the Vagrant VM's VagrantFiles to a common local folder outside of the vagrant directory such that each Vagrant instance can still read the folder and provision the server?
Edited --
Based on comment from #Treminio, here is the portion of my VagrantFile showing the attempt to declare an absolute path from host computers root:
config.vm.provision "puppet" do |puppet|
puppet.manifest_file = "init.pp"
puppet.manifests_path = "/Users/jdugger/vm/puppet/manifests"
puppet.module_path = "/Users/jdugger/vm/puppet/modules"
puppet.hiera_config_path = "/Users/jdugger/vm/puppet/hieradata"
end
... and the error response by Vagrant:
==> default: Configuring and enabling network interfaces...
==> default: Mounting shared folders...
default: /vagrant => /Users/jdugger/vm/pupt/vagrant
default: /vagrant_data/scripts => /Users/jdugger/scripts
default: /tmp/vagrant-puppet/modules-169f1d27ef31a534405e2e9fcde2eedf => /Users/jdugger/vm/puppet/modules
default: /tmp/vagrant-puppet/manifests-be5a69bfb646cf9329b8921f221ffab8 => /Users/jdugger/vm/puppet/manifests
==> default: Running provisioner: puppet...
The `puppet` binary appears not to be in the PATH of the guest. This
could be because the PATH is not properly setup or perhaps Puppet is not
installed on this guest. Puppet provisioning can not continue without
Puppet properly installed.
This response may not be because of the puppet path - not sure - It appears that puppet is not on the guest box (isn't it supposed to be running from Vagrant?). No version comes up when with:
[vagrant#localhost ~]$ puppet --version
Response is:
-bash: puppet: command not found
Update ---
#Treminio is correct. I have been able to provision with puppet manifests and modules external to the vagrant/ directory. The Path problem appears to be because Puppet is not installed on the guest VM. To resolve this I added a shell script found here:
http://garylarizza.com/blog/2013/02/01/repeatable-puppet-development-with-vagrant/
This was added just before the puppet provisioning declaration. Just as a note there doesn't seem to be a lot of advanced examples that demonstrate the external file capability or that you need to install puppet outside of the puppet provisioner.
However each Vagrant VM requires a complete self contained copy of all of the Git repos in order to stand up just one VM.
This is incorrect.
What you want to change is the puppet.module_path value.
It can be any location on your host's disk, and Vagrant will automatically mount it inside your VM.

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.

How to use vagrant in development and how to use shared folders?

I (a struggling newbie in vagrant) have done setup a vagrant environment for development. i have been provided with vagrant file
Vagrant.configure("2") do |config|
config.vm.box = 'precise64'
config.vm.box_url = 'http://files.vagrantup.com/precise64.box'
config.vm.network :forwarded_port, guest: 80, host: 8080
config.vm.provision :puppet do |puppet|
puppet.module_path = "config/puppet/modules"
puppet.manifests_path = "config/puppet/manifests"
puppet.manifest_file = "base.pp"
end
config.vm.provider :virtualbox do |v|
v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
end
end
the config/puppet/manifests contains following base.pp file
Exec {
path => "/usr/bin:/bin:/usr/sbin:/sbin"
}
stage { 'first':
before => Stage['main']
}
class {
'system': stage => first;
'mysql': stage => main;
'apache': stage => main;
'php': stage=> main;
'git': stage=> main;
'cake': stage=> main;
}
and config/puppet/modules containing directories apache,cake,git,mysql,php and system.
What i did so far is
1) Installed VirtualBox
2) Installed Vagrant
3) Vagrant up (as specified everywhere in net)
What i got is
1) a virtualbox (having no GUI)
2) SSH connection to virtaul box
3) and a shared folder.
now i have some questions so that i can understand it well
1) Am i going in right direction in order to setup vagrant?
2) What is precise64.box(just console box), can't i add ubuntu as a box and everything set up(i.e. php, apache n other modules specified in puppet modules) in that ubuntu?
3) Where does puppet install all these modules? in Host(Windows) or in Guest(precise64)?
4) What config.vm.network :forwarded_port, guest: 80, host: 8080 do?
5) what does shared folder do? and where does the shared folder reside in virtual box(precise64) and what i could/should do with this shared folder?
6) where do i install Netbeans/Eclipse in order to develop my code?
7) Any references/blog that describe vagrant and its advantages in and out?
I am trying to understand but couldn't figure it out how to understand vagrant (as a developer) and develop something. Any help or explanation would be appreciable and i guess these could be most common points that is hard for any newbie to understand.
1) Yes, looks like you're doing everything right to me. There's really no right or wrong if it works, your config looks pretty standard. (Not sure about your puppet config...I've never used that)
2) .box files are basically install cds that are packaged specifically for vagrant. In this case, you're downloading and installing http://files.vagrantup.com/precise64.box, which is essentially a bare-bones off the shelf ubuntu 12.04 64 bit server. You can find other prepackaged boxes here. The point of vagrant is to be able to start with a barebones OS and built it up by use of provisioning files (chef, puppet, bash, etc.).
3) Everything in vagrant is very self contained within the VM its creating, I don't know much about puppet but I would assume it works much the same way that the bash provisioning files I use work. It boots the VM, then runs your provisioning scripts within the VM so that you have a reproducible VM creation process.
4) Port forwarding. guest: 80, host :8080 means that anything within the VM (guest) serving on port 80 will be available on the host (your pc) at http://localhost:8080.
5) Shared folders are AWESOME. Basically, your VM will have access to a folder from your host machine which is incredibly helpful for question number 6. Doing something like:
config.vm.synced_folder "src/", "/vagrant"
will make the src directory in your project (on the host) available to the vm at the mount point /vagrant. So you can have an IDE installed on your host, edit files in src and they'll automatically be available in your VM at /vagrant. More on that here.
6) On your host machine. See answer to number 5.
7) Perhaps google is your best friend for this one. The biggest advantage for me is that we can check our Vagrantfile into our git repo next to the rest of our application code and any new member of our team can have the application running locally within minutes by navigating to the directory and running vagrant up. Mess something up within the VM and need to start fresh? vagrant destroy -> vagrant up. Not having to install a bunch of packages specific to an application on your host machine is invaluable.

puppet looking for hiera.yaml in the wrong place

I want puppet to look for hiera.yaml in /etc but it's looking for it in /etc/puppet. I put a line into puppet.conf:
hiera_config = /etc/hiera.yaml
But still gives me the hiera.yaml update warning when I run the script.
I'm running the script from Vagrant 1.2.2. Using puppet 3.2.2
I'm running Centos 6.4 in a vm.
I found that the puppet provisioner in vagrant now support hiera_config_path which does exactly what is desired.
config.vm.provision :puppet do |puppet|
# path on host machine to hiera.yaml
puppet.hiera_config_path = '/Users/me/vms/hiera/hiera.yaml'
# This sets the relative path for hiera data directories
puppet.working_directory = '/Users/me/vms/hiera'
end
This is documented in Vagrant: Up and Running but I didn't find it until I started looking into the vagrant source to implement this feature myself.
Hmmm... On Vagrant 1.2.2 and Puppet 3.2.3, I am able to set hiera_config in puppet.conf without problems. I would double-check that you are editing /etc/puppet.conf on the Vagrant vm, not on the host machine, and that the hiera_config line is the [main] block, not just in the [master] block.
If both of those conditions are true and it is still not working, you might try explicitly setting hiera_config in your Vagrantfile:
config.vm.provision :puppet do |puppet|
...
puppet.options = '--hiera_config=/etc/hiera.yaml'
end
Good luck!
Puppet provisioning runs as root user, not vagrant, so that's why it doesn't take notice of your puppet.conf in /vagrant.
If you run puppet config print inside the vm from user vagrant and root you see ALL puppet config settings per user and compare.

Resources