0

I have a vagrant file that uses chef to help install things:

Vagrant.configure(2) do |config|
  config.vm.box = 'opscode-ubuntu-12.04_chef-11.4.0'
  config.vm.box_url = 'https://opscode-vm-bento.s3.amazonaws.com/vagrant/opscode_ubuntu-12.04_chef-11.4.0.box'
  config.vm.network :forwarded_port, guest: 3000, host: 3000

  config.vm.provider(:virtualbox) do |vb|
    vb.customize [
      "modifyvm", :id,
      "--memory", "1024",
      "--cpus",   "4"
    ]
  end

  config.vm.provision :shell, inline: %Q{
    sudo apt-get install -y postgresql-client
  }

  config.vm.provision :chef_solo do |chef|
    chef.cookbooks_path = ["cookbooks"]
    chef.add_recipe :apt
    chef.add_recipe 'postgresql::server'
    chef.add_recipe 'build-essential'
    chef.add_recipe 'rvm::vagrant'
    chef.add_recipe 'rvm::system'
    chef.add_recipe 'git'
    chef.json = {
      :postgresql => {
    :version => '9.3'
      },
      "postgresql" => {
        "password" => {
          "postgres" => "kshgfi3ret3hihjfbkivtbo3ity835"
        }
      },
      "database" => {
        "create" => ["aisisplatform"]
      },
      :git   => {
        :prefix => "/usr/local"
      },
      :rvm => {
        'rubies' => [ 'ruby-2.1.0' ],
        'default_ruby' => 'ruby-2.1.0',
        'vagrant' => {
          :system_chef_solo => '/usr/bin/chef-solo'
        }
      },
    }
  end
end

There are a few issues with this:

  • Through out the vagrant up start up I get warnings like this:

    /tmp/vagrant-chef-1/chef-solo-1/cookbooks/rvm/libraries/rvm_chef_user_environment.rb:32: warning: class variable access from toplevel

  • The next issue is that things don't work properly, some times the vm sees PostgreSQL, through the psql command, sometimes it doesn't know what it is and states it's not installed. when it does see it, it states that psql: FATAL: role "vagrant" does not exist

  • The final issue is that when the vm boots up there is well over 200 updates of both regular and security. I would like this to be taken care of when the vm is set up the first time, via vagrant up. I tried doing:

    config.vm.provision :shell, inline: %Q{ sudo apt-get update sudo apt-get upgrade -y }

But when the script runs I get TON of errors about stdn and so on and so forth. So, what do I do to fix these? what's wrong with my vagrant file?

LogicLooking
  • 916
  • 1
  • 16
  • 32

1 Answers1

4

I adapted the vagrant file to use the omnibus and berkshelf plugins. The former will ensure chef is at the desired version and the latter keeps the cookbooks up-to-date.

I also noted the "class variable access" warnings, whose root cause is presumably buried in the rvm cookbook. I didn't look deeper because my Vagrant run completed without error.

Example

$ tree
.
├── Berksfile
└── Vagrantfile

Berksfile

site :opscode

cookbook "apt"
cookbook "postgresql"
cookbook "build-essential"
cookbook "rvm", :github => "fnichol/chef-rvm"
cookbook "git"

Vagrantfile

Vagrant.require_plugin "vagrant-omnibus"
Vagrant.require_plugin "vagrant-berkshelf"

Vagrant.configure(2) do |config|

  # Box config
  config.vm.box = 'precise64'
  config.vm.box_url = 'http://files.vagrantup.com/precise64.box'

  # Plugin config
  config.omnibus.chef_version = :latest
  config.berkshelf.enabled = true

  # Network config
  config.vm.network :forwarded_port, guest: 3000, host: 3000

  # Virtual config
  config.vm.provider(:virtualbox) do |vb|
    vb.customize [
      "modifyvm", :id,
      "--memory", "1024",
      "--cpus",   "4"
    ]
  end

  # Provisioner config
  config.vm.provision :chef_solo do |chef|
    chef.add_recipe 'apt'
    chef.add_recipe 'postgresql::client'
    chef.add_recipe 'postgresql::server'
    chef.add_recipe 'build-essential'
    chef.add_recipe 'rvm::system'
    chef.add_recipe 'git'
    chef.json = {
      :postgresql => {
        :version => '9.3'
      },
      "postgresql" => {
        "password" => {
          "postgres" => "kshgfi3ret3hihjfbkivtbo3ity835"
        }
      },
      "database" => {
        "create" => ["aisisplatform"]
      },
      :git   => {
        :prefix => "/usr/local"
      },
      :rvm => {
        'rubies' => [ 'ruby-2.1.0' ],
        'default_ruby' => 'ruby-2.1.0',
        'vagrant' => {
          :system_chef_solo => '/usr/bin/chef-solo'
        }
      },
    }
  end
end

Notes:

  • A standard Ubuntu image can be used. The omnibus plugin will install Chef 11.10 automatically
  • The "rvm::vagrant" recipe was removed as unncessary. Chef is installed using the omnibus installer and will therefore have it's own embedded ruby version
  • Used the "postgresql::client" recipe instead of a shell provisioner.
Mark O'Connor
  • 76,015
  • 10
  • 139
  • 185
  • Your's gave me errors: `stdin: is not a tty` and `/tmp/vagrant-chef-1/chef-solo-1/cookbooks/rvm/libraries/rvm_chef_user_environment.rb:49: warning: class variable access from top-level` which repeated it's self 3 more times. Not to meant ion doing `vagrant ssh` after followed by a `psql` gives me: `psql: FATAL: role "vagrant" does not exist` I thought this was all take care of for me? – LogicLooking Feb 15 '14 at 18:26
  • The "tty" and "class variable" messages are warnings, not errors. Chef completes doesn't it? As for your psql error this is a separate issue which *you* have asked here: http://stackoverflow.com/questions/21801837/psql-fatal-role-vagrant-does-not-exist – Mark O'Connor Feb 15 '14 at 19:28