Skip to content

Instantly share code, notes, and snippets.

@holms
Last active November 27, 2017 18:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save holms/7239334 to your computer and use it in GitHub Desktop.
Save holms/7239334 to your computer and use it in GitHub Desktop.
install chef-solo and bootstrap a node
#--------------------------------------------------------------------------------------------------------#
# #
# *** Chef repository setup together with chef-solo, knife-solo, libririan-chef and vagrant *** #
# #
# This guide is for people who has around 2-3 vm's (on vps or just dedicated server) with their side #
# project. My intension just to show you, how to create chef repository, and provision your vm's from #
# laptop/desktop without using chef server/client and additional fuss. Also this guide includes vargrant #
# setup just for testing your recipes. #
# -------------------------------------------------------------------------------------------------------#
# Install ruby 1.9.x, check install-ruby.sh file below
# I'll asume you're on root
# Install chef-solo
gem install chef
# Install librarian-chef for automatic dependency gathering
gem install librarian-chef
# Install knife-solo, it let's you to privision vm's easily
gem install knife-solo
# configure knife
knife configure -r . --defaults
# Initialise chef repository. This will also setup libriarian-chef and .gitignore for you
knife solo init myrepo
# configure git repo, you probably wanna have this it git repo right ;)?
git init . && git add .
git commit -m "Init chef repository"
# now go and prepare your vm with vagrant or/and virtualbox. see prepare-vm.sh file below
# it's better to create ~/.ssh/config file on hostmachine where you'd give a hostname to your ip's
# then knife will greate nicely named files in "node" directory
#
# ~/.ssh/config Example:
#
# Host mybox-client
# Hostname 10.0.0.0
# User vagrant
#
# Host mybox-server
# Hostname 10.0.0.0
# User vagrant
# ok let's prepare (provision) our vm with chef
knife solo prepare user@ip_of_my_vm
# after last step in ./node directory you've got two files with your machine hostname
# edit name, add cookbooks to proceseed:
vim nodes/mybox-server.json
# now it's about time to read docs about how to codel in chef's SDL.
# i'll just give you a short example how to install existing cookbooks from opscode repo.
# i'll be using logstash cookbook for installing nice logging tool with web panel
{
"run_list":[
"recipe[logstash::server]"
]}
# next we will use librarian to handle all cookbooks depedencies
vim Cheffile
# add this line:
# cookbook 'logstash'
# now "cook" your servers!
knife solo cook mybox-client
knife solo cook mybox-server
# Debian/Ubuntu
apt-get install ruby1.9.1 ruby1.9.1-dev -y
# Osx
sudo port -v install ruby19
# On Centos you have to use rvm
# google for it, i'll add it later on here
# now you need to prepare virtual machine or any other machine you can access
# steps for ubuntu guest (works for debian too): http://matschaffer.com/2011/06/minimal-ubuntu-virtualbox/
#
# For vm host:
# * install virtualbox (apt-get install virtualbox)
# * in you vm settings set network adapter to "bridge"
#
# For vm guest:
# * install execute: "apt-get install ruby1.9
# * install sshd : "apt-get install openssh-server
# * install guest-additions: "apt-get install virtualbox-guest"
#
# Make sure you can login to your vm via ssh and go back o host machine
# for virtualbox check file prepare-virtualbox.sh
# If you want multiple-vm's, for me vagrant was a solution
# Get latest vagrant deb for debian/ubuntu. For osx just download and install dmg
# (Don't bother installing it from package manager or gems, it's and old version in there which has tons of bugs)
wget http://files.vagrantup.com/packages/a40522f5fabccb9ddabad03d836e120ff5d14093/vagrant_1.3.5_x86_64.deb
deb -i vagrant_1.3.5_x86_64.deb
# Add a new ubuntu/debian box from here,
# I'd advice stable version, wich no chef and puppet, cause we will provision that vm manually
# http://www.vagrantbox.es/ (just copy a link, don't download it)
vagrant box add ubuntu http://puppet-vagrant-boxes.puppetlabs.com/ubuntu-server-12042-x64-vbox4210-nocm.box
# prepare configuration, let's assume you want two boxes, it's saves time on your learning curve.
cat > ~/Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch even if you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "ubuntu12"
config.vm.define :mybox-client do |cfg|
cfg.vm.hostname = "mybox-client"
cfg.vm.network "public_network"
end
config.vm.define :mybox-server do |cfg|
cfg.vm.hostname = "mybox-server"
cfg.vm.network "public_network"
end
end
# go to directory where Vagrantfile landed
cd ~
# launch machines, to launch both "vagrant up"
vagrant up mybox-server
vagrant up mybox-client
# after this will finish you can ssh to your machine, do this for both and copy ip from ifconfig output on guest machines
vagrant ssh mybox-server
@matschaffer
Copy link

This looks reasonable at first glance. Is there a particular error you're running into?

I hear you that the opscode docs are a little server-centric. But that is their business model, so hard to give them too much slack for it. ;)

@holms
Copy link
Author

holms commented Nov 7, 2013

Well, first of all, their docs are completely not intuitive for me. I've learned puppet for one day. I mean, I've prepared puppet-server, puppet-client really quickly. Everything was easy to understand from manual, with proper steps, and concept in between.

When you go to chef-docs you want to kill your self because, nobody even explains a concept, and even more examples are just random. What is the order of steps? In section where you have to setup open source chef, that place where you put knife to your workstation - steps are in reverse order! It took me time to figure out what goes one. My learning curve is really complicated.

Docs are missing proper introduction too, here's one which is just perfect: http://learnchef.getharvest.com/introduction.html
After that introduction, I've started to understand what I'm actually doing with commands. It's too much terms everywhere, it's too much information given together. Less is more.

@kaspergrubbe
Copy link

@holms And it is still like this...

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