Skip to content

Instantly share code, notes, and snippets.

@dirksiemers
Last active December 20, 2015 08:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dirksiemers/6098269 to your computer and use it in GitHub Desktop.
Save dirksiemers/6098269 to your computer and use it in GitHub Desktop.

create a project folder with git

git init my_project
cd my_project

(optional)

echo /cookbooks >> .gitignore
echo /tmp >> .gitignore
git add .gitignore
git commit -m "ignoring cookbooks & tmp directory created by librarian"

create a Gemfile

touch Gemfile

edit Gemfile

source "https://rubygems.org"
gem "chef"
gem "librarian-chef"

running bundler

bundle

init librarian

librarian-chef init

edit Cheffile

site 'http://community.opscode.com/api/v1'

cookbook 'apt', '1.7.0'
cookbook 'git',
  git: 'https://github.com/fnichol/chef-git.git'
cookbook 'rvm',
  :git => 'https://github.com/fnichol/chef-rvm'
cookbook 'build-essential'
cookbook 'postgresql',
  :git => 'https://github.com/findsyou/cookbooks',
  :ref => 'postgresql-improvements'
cookbook 'nginx'

Install cookbooks

librarian-chef install

create a role for a runlist

mkdir roles
touch roles/vagrant.rb

edit role

name "vagrant"

run_list %w(
  recipe[apt]
  recipe[build-essential]
  recipe[git]
  recipe[rvm::vagrant]
  recipe[rvm::system]
  recipe[postgresql]
  recipe[nginx]
)

override_attributes(
  "rvm" => {
    "default_ruby"      => "ruby-1.9.3-p392",
    "user_default_ruby" => "ruby-1.9.3-p392"
  }
)

add to version control

git add Cheffile
git add Cheffile.lock
git commit -m "I want these particular versions of these particular cookbooks."

init vagrant

vagrant init

edit Vagrantfile

Vagrant.configure("2") do |config|
  config.vm.box = "lucid32"
  config.vm.box_url = "http://files.vagrantup.com/lucid32.box"
  config.vm.network :forwarded_port, guest: 80, host: 8080
  config.vm.network :private_network, ip: "192.168.33.10"

  config.vm.provision :chef_solo do |chef|
    chef.cookbooks_path = ["cookbooks"]
    chef.roles_path = "roles"
    chef.add_role "vagrant"
  end
end

start vagrant

vagrant up
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment