To install stuff needed to run chef in a solo mode (Small one or two server configuration):
gem install knife-solo
To setup chef after it has been installed:
knife configure -r . --defaults
Sidebar - in order to create a host-only network in virtual box, to make it easy to SSH into it from the host machine.
-
VirtualBox -> Preferences
-
Select Network
-
Push network card with "+" this creates a new Host-only network.
-
With the VM instance OFF:
- Select VM Settings.
- Select Adapter 2.
- Toggle Enable Network Adapter.
- Set Attached To: Host-only Adapter.
- Name: The name of the host-only network created previously - default vboxnet0
- Power up the VM.
-
You also need to make sure that the host-only network doesn't conflict with the IP address set to what you plan on using below.
- Select the host-only adapter in VM settings.
- Edit, make sure it doesn't conflict with the desired address (192.168.56.105 for the below example).
-
Configure operating system as per normal. For Ubuntu:
-
sudo vim /etc/network/interfaces
-
Add the following: auto eth1 iface eth1 inet static address 192.168.56.101 netmask 255.255.255.0
To create a new 'kitchen' or chef project:
knife kitchen my_kitchen
Cookbooks, or predefined scripts for setting up a whole ton of cookbooks from different serverside tools can be found on github. However, before you can install cookbooks you must initialise your new kitchen as a git repository:
cd my_kitchen
git init
git add cookbooks/
git add data_bags/
git add nodes/
git add roles/
git add site-cookbooks/
git add solo.rb
git commit -a -m "Created new kitchen."
Then installing a particular preconfigured cookbook:
knife cookbook site install postgresql
To create a cookbook:
knife cookbook create widget
The cookbook then needs to be added to a run list. Run lists are on a server per server (node per node) basis. To prepare a new server (node) to receive a chef cookbook and create a run list:
knife solo prepare [email protected]
To prepare a server with a different version of Chef (say to avoid compatibility cookbook compatibility issues) pass the omnibus version in:
knife solo prepare [email protected] --omnibus-version 10.24.0
Then to add postgresql to the run list, edit the newly created json file in nodes:
vim nodes/192.168.56.101.json
It should contain the following, the run list instructs chef what recipes to invoke on the server when you cook, while the postgresql element is a configuration element required by the postgresql cookbook:
{
"postgresql":{"password":{"postgres":"test"}},
"run_list": ["recipe[postgresql::server]"]
}
Then cook the server using the following command:
knife solo cook [email protected]