Setup a chef server with vagrant
Ruby
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
roles
.gitignore
Berksfile
Berksfile.lock
Gemfile
Gemfile.lock
Readme.md
Vagrantfile

Readme.md

Vagrant Chef Server

http://luuuc.github.io/vagrant-chef-server

Requirements

You need the following.

  1. virtualbox (https://www.virtualbox.org)
  • The latest VirtualBox platform packages.
  • The latest VirtualBox Extension Pack.
  1. ruby (https://www.ruby-lang.org)
  1. Chef (http://www.opscode.com)
  1. Vagrant (http://www.vagrantup.com)

  2. Omnibus Vagrant plugin (https://github.com/schisamo/vagrant-omnibus)

  • In you terminal issue the command vagrant plugin install vagrant-omnibus
  1. Berkshelf Vagrant plugin (https://github.com/riotgames/vagrant-berkshelf)
  • In you terminal issue the command vagrant plugin install vagrant-berkshelf

Quick Install

First clone this repository then

$ bundle install --path vendor
$ berks install --path cookbooks
$ vagrant up

Visit https://10.33.33.33/version to check if everything is working. Then https://10.33.33.33 to access the web interface (admin/p@ssw0rd1). Change to a secure password and regenerate certificates.

Do it yourself

Project Setup

Create and move to the project folder.

$ mkdir vagrant-chef-server
$ cd vagrant-chef-server

Create a gem file.

$ cat > Gemfile <<EOF
source "https://rubygems.org"

gem "knife-solo"
gem "berkshelf"

EOF

Install the gem locally to a new 'vendor' folder.

$ bundle install --path vendor

Create a knife solo (a.k.a chef solo) folder structure.

$ knife solo init .

Create a Berkshelf file to manage cookbooks.

$ cat > Berksfile <<EOF
site :opscode

cookbook 'chef-server'

EOF

Install Berkshelf cookbooks.

$ berks install --path cookbooks

Configure Chef Server Node

Create “chef.json” file in the role folder with the following content.

{
  "name": "chef",
  "chef_type": "role",
  "json_class": "Chef::Role",
  "description": "The base role for Chef Server",
  "default_attributes": {
    "chef-server": {
      "version": "latest",
      "configuration": {
        "chef_server_webui": {
          "enable": true
        }
      }
    }
  },
  "run_list": [
    "recipe[chef-server::default]"
  ]
}

You can change or find more info to the above settings at https://github.com/opscode-cookbooks/chef-server/blob/master/attributes/default.rb

Done !

Configure Vagrant

Create a vagrant intialization file with the following command.

vagrant init

Change your vagrant to file to:

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
  config.vm.box = "precise64"
  config.vm.box_url = "http://files.vagrantup.com/precise64.box"

  config.vm.network :private_network, ip: "10.33.33.33"
  config.vm.network :forwarded_port, guest: 80, host: 8000
  config.vm.network :forwarded_port, guest: 443, host: 8443

  config.vm.provider :virtualbox do |v|
    v.name = "chef-server"
    v.customize ["modifyvm", :id, "--cpus", "2"]
    v.customize ["modifyvm", :id, "--memory", "1024"]
  end

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

  config.vm.provision :chef_solo do |chef|
    chef.cookbooks_path = "cookbooks"
    chef.roles_path = "roles"
    chef.data_bags_path = "data_bags"
    
    chef.add_role("chef")
  end
end

Launch the virtual machines.

$ vagrant up

Visit https://10.33.33.33/version to check if everything is working. Then https://10.33.33.33 to access the web interface (admin/p@ssw0rd1). Change to a secure password and regenerate certificates.

You can access your chef server from another computer in the same network with https://your-machine-ip:8443

Connect through ssh to copy your chef server keys.

$ vagrant ssh chef
vagrant@precise64:~$ sudo cp /etc/chef-server/*.pem /vagrant/.chef/

Knife configuration

Configure knife

$ knife configure -i
  • chef server URL: https://10.33.33.33
  • clientname: admin
  • admin client's private key: .chef/webui.pem
  • validation key: .chef/validation.pem

Check knife configuration:

$ knife client list
> chef-validator
> chef-webui

That's it! You're now ready to cook.