• We will use Virtualbox, you can skip that part if you have a remote host
  • We use OSX as the Host, again. Skip this part if you already have a target server

Step 1: Create Chef Environment

Setup the chef-repo

Use the super easy way

  • Create you account at http://getchef.com/
  • Download the starter pack
  • extract it somewhere
  • cd into the repo folder (chef-repo)

Build a new repo or re-use what you already have

  • create the base folder
mkdir -p chef-repo/.chef
mkdir -p chef-repo/cookbooks
mkdir -p chef-repo/environments
mkdir -p chef-repo/roles
  • add your knife.rb and keys to .chef

Install Chef and Berkshelf

  • create a Gemfile
cat Gemfile
source 'https://rubygems.org'

# get Berkshelf 3.0.beta

gem 'chef'
gem "berkshelf", github: "berkshelf/berkshelf"
  • install your bundle
bundle install
  • create Berksfile
cat Berksfile
source "https://api.berkshelf.com"

Step 2 (optional): Install Virtualbox, Vagrant on OSX with Chef

Create the Cookbook to do so

This step is optional if you already have a running remote machine with ssh access.

  • create a homenetwork cookbook
  • knife cookbook create homenetwork
  • add some deps to the cookbook

cookbooks/homenetwork/metadata.rb

metadata.rb
name             'homenetwork'
maintainer       'YOUR_NAME'
maintainer_email 'YOUR_EMAIL'
license          'All rights reserved'
description      'Installs/Configures homenetwork'
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version          '0.1.6'

depends 'dmg'
depends 'vagrant'
depends 'homebrew'

cookbooks/homenetwork/recipes /testlab.rb

#testlab

include_recipe "homebrew"

dmg_package 'Virtualbox' do
  source 'http://download.virtualbox.org/virtualbox/4.3.6/VirtualBox-4.3.6-91406-OSX.dmg'
  type   'pkg'
end

node.set.vagrant.url = "https://dl.bintray.com/mitchellh/vagrant/Vagrant-1.4.3.dmg"
node.set.vagrant.sha = "e7ff13b01d3766829f3a0c325c1973d15b589fe1a892cf7f857da283a2cbaed1"

node.set.vagrant.upgrade

include_recipe "vagrant"

add it to the Berksfile

echo “cookbook 'homenetwork', :path => ‘cookbooks/homenetwork’” >> Berksfile
  • (optional, as this happens implicit) install cookbooks
bundle exec berks install
  • upload to the Chef server
bundle exec berks upload 
  • bootstrap the osx box with the recipe
knife bootstrap --sudo -x <osx-user> <ip-of-osx-box> -r homenetwork::testlab
Bootstrapping Chef on <ip-of-osx-box>
<ip-of-osx-box> knife sudo password:
Enter your password:

Step 3 (optional) Create a new VM

first incarnation is manual

  • create a linux box with the UI
  • give it some ram (e.g. 2GB) and some disk (e.g. 40GB)
    • download Ubuntu Server
    • use a bridged config to use it directly in your network
    • install the box
    • reboot
    • configure your router/dhcp so that this box always gets the same ip

Step 4 Install Gitlab on Virtualbox

  • add the gitlab cookbook to your Chef server
echo “cookbook ‘gitlab', git: ‘https://gitlab.com/gitlab-org/cookbook-gitlab.git'” >> Berksfile
  • update the repo and upload the cookbooks
bundle exec berks install
bundle exec berks upload
  • create a role with the config

roles/gitlab.json

{
  "name": "gitlab",
  "description": "",
  "json_class": "Chef::Role",
  "default_attributes": {
    "gitlab": {
      "host": "gitlab.example.com",
      "url": "http://gitlab.example.com/",
      "email_from": “gitlab@example.com",
      "support_email": “support@example.com",
      "database_adapter": "postgresql",
      "database_password": “set me“
    },
    "postgresql": {
      "password": {
        "postgres": “set “me
      }
    },
    "postfix": {
      "mail_type": "client",
      "myhostname": "mail.example.com",
      "mydomain": "example.com",
      "myorigin": "mail.example.com",
      "smtp_use_tls": "no"
    }
  },
  "override_attributes": {
  },
  "chef_type": "role",
  "run_list": [
    "recipe[postfix]",
    "recipe[gitlab::default]"
  ],
  "env_run_lists": {
  }
}
  • upload the role
knife role from file gitlab.json
  • bootstrap the node
$ knife bootstrap --sudo -x <user-you-created> <ip-of-gitlab> -r role[gitlab]
Bootstrapping Chef on <ip-of-gitlab>
<ip-of-gitlab> knife sudo password:
Enter your password:

Step 5

  • enjoy :-)

Interested in Cloud or Chef Trainings? Have a look at our Commandemy Trainings page. Need help migrating to the cloud? Check out Infralovers.

comments powered by Disqus
Blog Tags