简体   繁体   English

流浪汉无法正常工作

[英]Vagrant not working properly

I have a vagrant file that uses chef to help install things: 我有一个流浪者文件,该文件使用Chef来帮助安装东西:

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: 在整个vagrant up启动过程中,我得到如下警告:

    /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. 下一个问题是,某些情况下vm不能通过psql命令查看PostgreSQL,但有时它不知道它是什么,并声明未安装。 when it does see it, it states that psql: FATAL: role "vagrant" does not exist 当它确实看到它时,它指出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. 最后一个问题是,当虚拟机启动时,常规和安全性的更新都超过200个。 I would like this to be taken care of when the vm is set up the first time, via vagrant up . 我希望通过vagrant up第一次设置虚拟机时得到照顾。 I tried doing: 我试着做:

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

But when the script runs I get TON of errors about stdn and so on and so forth. 但是在脚本运行时我得到错误的TON stdn等等等等。 So, what do I do to fix these? 那么,我该如何解决这些问题? what's wrong with my vagrant file? 我的流浪文件有什么问题?

I adapted the vagrant file to use the omnibus and berkshelf plugins. 我修改了流浪汉文件以使用omnibus和berkshelf插件。 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. 我还注意到了“类变量访问”警告,其根本原因大概是藏在rvm食谱中。 I didn't look deeper because my Vagrant run completed without error. 我看起来不深,因为我的Vagrant运行已完成,没有错误。

Example

$ tree
.
├── Berksfile
└── Vagrantfile

Berksfile Berksfile

site :opscode

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

Vagrantfile 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. 可以使用标准的Ubuntu映像。 The omnibus plugin will install Chef 11.10 automatically omn​​ibus插件将自动安装Chef 11.10
  • The "rvm::vagrant" recipe was removed as unncessary. “ rvm :: vagrant”配方被删除,因为不必要。 Chef is installed using the omnibus installer and will therefore have it's own embedded ruby version Chef是使用omnibus安装程序安装的,因此将拥有其自己的嵌入式ruby版本
  • Used the "postgresql::client" recipe instead of a shell provisioner. 使用“ postgresql :: client”配方而不是Shell设置程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM