Problems running Vagrant/Puppet on osx 10.7 - ruby

I'm just getting started with Vagrant and Puppet. I'm able to get a Virtualbox running but now I want to automate the software that gets installed on it.
In my Vagrantfile I have:
Vagrant::Config.run do |config|
config.vm.box = "precise64"
config.vm.forward_port 80, 9090
config.vm.forward_port 27017, 27017
config.vm.provision :puppet do |puppet|
puppet.manifests_path = "manifests"
puppet.manifest_file = "default.pp"
end
end
in manifests/default.pp I have:
Exec { path => [ "/bin/", "/sbin/" , "/usr/bin/", "/usr/sbin/" ] }
class php5{
package { "php5":
ensure => present,
}
}
include php5
However, when I run vagrant up I get the following error (snippet).
[default] Running Puppet with /tmp/vagrant-puppet/manifests/default.pp...
stdin: is not a tty
No LSB modules are available.
warning: Could not retrieve fact fqdn
err: /Stage[main]/Php5/Package[php5]/ensure: change from purged to present failed: Execution of '/usr/bin/apt-get -q -y -o DPkg::Options::=--force-confold install php5' returned 100: Reading package lists...
I'm not really sure where the error lies, so here is some further information which might be useful
Ruby version
$ ruby -v
ruby 1.8.7 (2011-12-28 patchlevel 357) [universal-darwin11.0]
gem sources
$ gem sources
*** CURRENT SOURCES ***
http://rubygems.org/
Update 1: Following this post I installed facter and puppet now runs ok but the main problem is still happening.
Update 2: Correct answer marked, but I wanted to share my entire manifest file http://pastebin.com/LGNhVPV7

The 'apt-get install' error is probably happening because the VM hasn't finished an 'apt-get update' before Puppet tries to do the 'apt-get install'. Puppet won't handle the 'apt-get update' on its own when you request that a package be installed, but you can spell out that it should happen in your manifest easily enough.
Try adding the apt class Mr Leach mentions in his http://johnleach.co.uk/words/771/puppet-dependencies-and-run-stages post. This should ensure that 'apt-get update' is run before any packages are installed.

Related

Provisioning Vagrant box with chef-solo and vagrant

I want to spin up a Vagrant box and provision a LAMP stack using chef-solo and berkshelf. Here's the steps I take:
berks cookbook my_project
Then in Berksfile:
site :opscode
cookbook 'wordpress', '~> 3.0.0'
cookbook 'apache2', '~> 3.2.2'
cookbook 'mysql', '~> 8.2.0'
cookbook 'php', '~> 2.2.0'
Then berks vendor cookbooks
The Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = '2'
Vagrant.require_version '>= 1.5.0'
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.hostname = 'unify-config-berkshelf'
if Vagrant.has_plugin?("vagrant-omnibus")
config.omnibus.chef_version = 'latest'
end
config.vm.box = 'bento/ubuntu-14.04'
config.vm.network :private_network, type: 'dhcp'
config.vm.provision :chef_solo do |chef|
chef.json = {
mysql: {
server_root_password: 'rootpass',
server_debian_password: 'debpass',
server_repl_password: 'replpass'
}
}
chef.run_list = [
"recipe[apache2]",
"recipe[apache2::mod_php5]",
"recipe[mysql::client]",
"recipe[mysql::server]",
"recipe[php]",
"recipe[php::module_mysql]"
]
end
end
Then I try to bring the box up with vagrant up. This is the error I get.
The following berks command failed to execute:
/Users/stoebelj/.rbenv/shims/berks --version --format json
The stdout and stderr are shown below:
stdout:
stderr: Ignoring ffi-1.9.14 because its extensions are not built. Try: gem pristine ffi --version 1.9.14
Ignoring nokogiri-1.6.7.1 because its extensions are not built. Try: gem pristine nokogiri --version 1.6.7.1
Ignoring unf_ext-0.0.7.2 because its extensions are not built. Try: gem pristine unf_ext --version 0.0.7.2
Ignoring wdm-0.1.1 because its extensions are not built. Try: gem pristine wdm --version 0.1.1
/Users/stoebelj/.rbenv/versions/2.3.1/lib/ruby/2.3.0/rubygems/dependency.rb:319:in `to_specs': Could not find 'berkshelf' (>= 0.a) among 47 total gem(s) (Gem::LoadError)
Checked in 'GEM_PATH=/opt/vagrant/embedded/gems', execute `gem env` for more information
from /Users/stoebelj/.rbenv/versions/2.3.1/lib/ruby/2.3.0/rubygems/dependency.rb:328:in `to_spec'
from /Users/stoebelj/.rbenv/versions/2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_gem.rb:65:in `gem'
from /Users/stoebelj/.rbenv/versions/2.3.1/bin/berks:22:in `<main>'
It appears that you are not using the ChefDK. Please note that Vagrant Berkshelf
works best when used with the ChefDK, and other installation methods are not
officially supported.
Please download and install the latest version of the ChefDK from:
https://downloads.chef.io/chef-dk
and follow the installation instructions. Do not forget to add the ChefDK to
your PATH.
I installed ChefDK from the URL given and /usr/local/bin/chef is in my PATH
What am I misunderstanding?
Update
A question below suggested I remove berkshelf from my rbenv, which did indeed get rid of the below error. Now I have a different error:
The Berkshelf version at "/usr/local/bin/berks" is invalid.
Vagrant Berkshelf requires >= 4.0, but the current version is .
Please download and install the latest version of the ChefDK from:
https://downloads.chef.io/chef-dk
and follow the installation instructions. Do not forget to add the ChefDK to
your PATH.
For context, I checked this which suggested I update my plugin. This did not work. I also tried removing the plugin and installing version 4.1 which also did not work.
And for context:
$ vagrant plugin list
vagrant-berkshelf (5.1.1)
vagrant-omnibus (1.5.0)
vagrant-share (1.1.6, system)
$ which berks
/usr/local/bin/berks
berks seems to work fine on its own but produces a warning I don't understand:
$ berks
W, [2017-02-13T13:46:00.590751 #3199] WARN -- : You are setting a key that conflicts with a built-in method Hashie::Mash#frozen? defined in Kernel. This can cause unexpected behavior when accessing the key via as a property. You can still access the key via the #[] method.
W, [2017-02-13T13:46:00.591227 #3199] WARN -- : You are setting a key that conflicts with a built-in method Hashie::Mash#frozen? defined in Kernel. This can cause unexpected behavior when accessing the key via as a property. You can still access the key via the #[] method.
W, [2017-02-13T13:46:00.591452 #3199] WARN -- : You are setting a key that conflicts with a built-in method VariaModel::Attributes#frozen? defined in Kernel. This can cause unexpected behavior when accessing the key via as a property. You can still access the key via the #[] method.
W, [2017-02-13T13:46:00.591672 #3199] WARN -- : You are setting a key that conflicts with a built-in method VariaModel::Attributes#frozen? defined in Kernel. This can cause unexpected behavior when accessing the key via as a property. You can still access the key via the #[] method.
W, [2017-02-13T13:46:00.629581 #3199] WARN -- : You are setting a key that conflicts with a built-in method VariaModel::Attributes#default defined in Hash. This can cause unexpected behavior when accessing the key via as a property. You can still access the key via the #[] method.
W, [2017-02-13T13:46:00.629737 #3199] WARN -- : You are setting a key that conflicts with a built-in method VariaModel::Attributes#default defined in Hash. This can cause unexpected behavior when accessing the key via as a property. You can still access the key via the #[] method.
Resolving cookbook dependencies...
Fetching 'unify_config' from source at .
Using apache2 (3.2.2)
Using build-essential (7.0.3)
Using compat_resource (12.16.3)
Using iis (5.0.5)
Using mingw (1.2.5)
Using mysql (8.2.0)
Using ohai (4.2.3)
Using php (2.2.0)
Using seven_zip (2.0.2)
Using unify_config (0.1.0) from source at .
Using windows (2.1.1)
Using xml (3.1.1)
Using yum-epel (2.1.1)
As shown in the command it is trying to run, the issue isn't the chef executable, it's berks. Remove the copy of that you installed via gems and makes sure the copy from ChefDK is working.
Ran into this issue couple days ago as well. Rolling back the version of ChefDK helped for me:
ChefDK 1.1.16
Coworker of mine was the one the dug up the reasoning, stating:
"vagrant uses berks -version --format json or something of the like to get the version of berks but running that command leads to some warning logs output by some dependency berks uses
which is why the version is blank"

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.

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

vagrant omnibus behind proxy

Ok, I'm trying to update chef-client with vagrant omnibus and proxyconf. I figured it would pull the proxy from the proxyconf, but it doesn't look that way. Here is my plugin list:
vagrant plugin list
vagrant-login (1.0.1, system)
vagrant-omnibus (1.4.1)
- Version Constraint: 1.4.1
vagrant-proxyconf (1.3.2)
- Version Constraint: 1.3.2
vagrant-share (1.1.0, system)
and my Vagrant file:
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.omnibus.chef_version = :latest
if Vagrant.has_plugin?("vagrant-proxyconf")
config.proxy.http = "my proxy"
config.proxy.https = "my proxy"
end
When i run it with vagrant up, the machine does not have an updated chef-client. I tried using the recipe[omnibus_updater] in my run list it still fails because another recipe is failing with a compile failure (because of the older version of chef-client, what a pain in the butt). Any ideas? Other than creating a new virtual box?
Update:
Running in debug mode doesn't show any errors using :latest. Updating to 11.12.8 gives the below error
vagrant-omnibus:
* '11.12.8' is not a valid version of Chef.
Logging into the vm shows $HTTP_PROXY and $HTTPS_PROXY set properly. Running the commands on the built vm works:
chef-client -v
Chef: 10.14.2
sudo gem update chef
chef-client -v
Chef: 11.12.8
Thing 1:
:latest does not error out when it fails to grab the artifact. Switching to a named version starts to fail to find the artifact which leads me to believe that it isn't getting through the proxy.
Thing 2:
I think this is a problem with omnibus in windows. I've found this pull that may fix it? https://github.com/schisamo/vagrant-omnibus/pull/89. I think this plug-in isn't using the settings set by poxy-conf.
CURRENTLY USING THIS WORKAROUND:
Set you http proxy in the windows cmd line
SET HTTP_PROXY=http://username:password#proxy:port

Vagrant with librarian-chef installing ruby via ruby_build & rbenv

over the last few weeks i have had to reinstall my whole working environment a few times and it can take a while so now i have an ambitious idea to use vagrant and librarian-chef to create my working environment so that all i have to do is run a bash script and viola i am in.
so the first time i did this was solo vagrant i went in and did everything and packaged it and it was great for only a while.. the package was 600mb so next idea was to have chef do it all. but i have never worked with chef before so i found librarian-chef basically i librarian-chef init and it makes a cheffile that you can specify cookbooks mine looks like this
site 'http://community.opscode.com/api/v1'
cookbook 'apt'
cookbook 'git'
cookbook 'build-essential'
cookbook 'ruby_build',
git: 'git://github.com/fnichol/chef-ruby_build'
cookbook 'rbenv',
git: 'git://github.com/fnichol/chef-rbenv'
cookbook 'sqlite',
git: 'git://github.com/opscode-cookbooks/sqlite.git'
cookbook 'nodejs',
git: 'http://github.com/mdxp/nodejs-cookbook'
cookbook 'mysql',
git: 'git://github.com/opscode-cookbooks/mysql.git'
cookbook 'redis',
git: 'git://github.com/brianbianco/redisio.git'
cookbook 'zlib',
git: 'git://github.com/opscode-cookbooks/zlib'
cookbook 'wkhtmltopdf',
git: 'git://github.com/firstbanco/chef-wkhtmltopdf.git'
and you tell vagrant and chef to build these when you call vagrent up
in the vagrantfile
config.vm.provision :chef_solo do |chef|
chef.cookbooks_path = ["cookbooks","site-cookbooks"]
chef.add_recipe "apt"
chef.add_recipe "build-essential"
chef.add_recipe "git"
chef.add_recipe "ruby_build"
chef.add_recipe "rbenv::install"
chef.add_recipe "sqlite"
chef.add_recipe "nodejs"
chef.add_recipe "mysql"
chef.add_recipe "redis"
chef.add_recipe "zlib"
chef.add_recipe "wkhtmltopdf"
end
now i was wondering if i could get ruby_build to install 1.9.3-p290 i found this question which seemed to have the answer but i am getting the following
Running chef-solo...
stdin: is not a tty
[2013-05-23T14:31:18+00:00] INFO: *** Chef 10.14.2 ***
[2013-05-23T14:31:18+00:00] INFO: Setting the run_list to ["recipe[apt]", "recipe[build-essential]", "recipe[git]", "recipe[ruby_build]", "recipe[rbenv::install]", "recipe[sqlite]", "recipe[nodejs]", "recipe[mysql]", "recipe[redis]", "recipe[zlib]", "recipe[wkhtmltopdf]"] from JSON
[2013-05-23T14:31:18+00:00] INFO: Run List is [recipe[apt], recipe[build-essential], recipe[git], recipe[ruby_build], recipe[rbenv::install], recipe[sqlite], recipe[nodejs], recipe[mysql], recipe[redis], recipe[zlib], recipe[wkhtmltopdf]]
[2013-05-23T14:31:18+00:00] INFO: Run List expands to [apt, build-essential, git, ruby_build, rbenv::install, sqlite, nodejs, mysql, redis, zlib, wkhtmltopdf]
[2013-05-23T14:31:18+00:00] INFO: Starting Chef Run for precise64
[2013-05-23T14:31:18+00:00] INFO: Running start handlers
[2013-05-23T14:31:18+00:00] INFO: Start handlers complete.
================================================================================
Recipe Compile Error
================================================================================
Chef::Exceptions::RecipeNotFound
--------------------------------
could not find recipe ruby_build for cookbook rbenv
[2013-05-23T14:31:19+00:00] ERROR: Running exception handlers
[2013-05-23T14:31:19+00:00] ERROR: Exception handlers complete
[2013-05-23T14:31:19+00:00] FATAL: Stacktrace dumped to /tmp/vagrant-chef-1/chef-stacktrace.out
[2013-05-23T14:31:19+00:00] FATAL: Chef::Exceptions::RecipeNotFound: could not find recipe ruby_build for cookbook rbenv
Chef never successfully completed! Any errors should be visible in the
output above. Please fix your recipes so that they properly complete.
how can i get ruby installed as well through ruby build is it possible or is this not possible
Librarian will install your cookbooks locally, but they aren't transferred to the remote vagrant box. You'll need to use the Vagrant Librarian Chef plugin.
See also:
Berkshelf
Vagrant Berkshelf
try adding ruby_build to the run list:
"run_list": [ "ruby_build", "recipe[main]" ]

Resources