How to set up Chef to work with Oktawave?
Posted by on 11.07.2013 16:16
Chef allows OCI management automation in Oktawave. With it, you can run instances that will include sets made by you (so-called regulations) and software configurations. Chef gives you the ability to run or remove instances on your account from the console.
In this guide, both the client and the Chef server will be installed on the same OCI in the ubuntu 12.04. The client can also be on your local computer on which you will create the rules and then sending them to the Chef server, where they will be applied to instances.
At the beginning we will start the installation of the Chef console client - Knife, with the module for managing instances in Oktawave. Lets make sure that we have the following packages on the system.
sudo apt-get install git ruby1.9.3
Now we will install the Knife, with the Oktawave-knife module.
sudo gem install knife-Oktawave
Create a directory .Chef in your home directory.
Inside of this directory create file knife.rb - file that contains our access data to Oktawave.
knife[:oktawave_login] = 'USER'
knife[:oktawave_password] = 'PASSWORD'
At this point, we have the opportunity to list our instance, enable/disable them, etc.
knife oktawave oci list
#lista dostępnych komend
Knife utility shows its full potential when we use it to create Oktawave instance. Not only Knife can automate this process, but each instance created in this way can have a prepared set of our application suite and be properly configured.
Before beginning installation of chef server, note that there are two more things.
We go to page http://www.opscode.com/chef/install/ and in the Chef Server tab we select the entries corresponding to the system, in which we want to install the software. Copy the link, download the Chef on the server and install it.
sudo dpkg -i chef-server_11.0.8-1.ubuntu.12.04_amd64.deb
Run the command to configure the Chef Server.
sudo chef-server-ctl reconfigure
In the /etc/chef-server directory should now contain files such as admin.pem and chef-validator.pem that our client need. So copy it to the previously created folder .chef.
cp /etc/chef-server/admin.pem ~/.chef/
cp /etc/chef-server/chef-validator.pem ~/.chef/
When we have a client installed on the local computer, we need to download these files from the server, eg using scp command.
The next step will be to clone (for example, to our home directory) chef-repo repository that contains the directory structure that will be used by the Knife. If the Knife is used on the local computer, then there should be a repository cloned.
git clone git://github.com/opscode/chef-repo
Now you are ready to connect the knife to the Chef server, using the knife configure -i command.
knife configure -i
Overwrite /root/.chef/knife.rb? (Y/N) Y
Please enter the chef server URL: [http://10316-1-405d24-01.services.oktawave.com:4000]
Please enter a name for the new user: [root] user
Please enter the existing admin name: [admin]
Please enter the location of the existing admin's private key:
Please enter the validation clientname: [chef-validator]
Please enter the location of the validation key:
Please enter the path to a chef repository (or leave blank): ~/chef-repo
Creating initial API user...
Please enter a password for the new user:
Configuration file written to /root/.chef/knife.
Sample answers to the questions you see above. Pay attention to the specified Chef Server URL, which is the domain name of your OCI, indicating the use of https. The paths to the key point to the place where he had copied the files admin.pem and chef-validator.pem, and the path to a chef repository is the location of the folder you created the cloned repository chef-repo.
This operation overwrites knife.rb, so again you need to add to it your Oktawave account credentials.
You can now also visit the Chef Server web panel, which can be found at https:// [domain_name_of_instance] (the same URL that you specified in the first question), log in with the newly created user data (answers to the questions: name for the new user and password for the new user). At this point, most of the section will be empty, but soon this will change.
Under the term bootstrap lies creation operation, start-up and the imposition of a set of ready-made configurations for OCI instance. Description of software included in the machine and how it should be configured, we call recipe. Recipes can be combined and accumulate in the role that we can assign to the created instance (in Chef it will be visible as a node).
We can create our own Recipes, in which Chef documentation may be helpful http://docs.opscode.com/essentials_cookbooks.html. We may also use Recipes prepared by other users, published here: http://community.opscode.com/, which is the resources that we will use.
Suppose that we are fans of zsh shell and git version control system. We would like for each of our instances to have this software already installed. We can search for ready recipe.
knife cookbook site search zsh
We found zsh recipe, that suits our needs, so we will install it.
knife cookbook site install zsh
We do the same with git (knife cookbook site install git). You should also use a recipe called apt (knife cookbook site install apt), which will provide up to date installation packages.
Downloaded recipes are still only in our local repository (~/chef-repo/cookbooks/), we can now upload them to the Chef server.
knife upload cookbooks
You can see the list of rules registered on Chef server by executing a command.
knife cookbook list
Or browse Cookbooks section in webpanel.
Now we will create a roll that contain recipes installed moment ago. In the first step, specify text editor that you will use.
And then create a role called mylinuxserver.
knife role create mylinuxserver
Now edit the opened file and in the run_list section put rules that you want to be applied on OCI and run with the mylinuxserver role.
We can finally start to run instances in Oktawave. Let us list of available machines.
knife oktawave template list
Lets choose, for example debian version 6.0.7, which Category ID is 6 and create an instance with name mydebian with assigned mylinuxserver role.
knife oktawave oci create -T 6 -N mydebian -r 'role[mylinuxserver]'
We can now observe OCI initialization process and applications from our recipes. If the process is interrupted for some reason, we can resume it, using the command specified by the program.
knife oktawave oci create --bootstrap-oci [ID_INSTNCJI] -r 'role[mylinuxserver]'
When finished, we get the OCI with installed zsh shell and git program. The instance is also a Chef nodem, on which we can apply additional recipes.
knife node list
This is just an example of how Chef with knife-Oktawave module can improve the work of the instances. More examples and information can be found in the Chef software documentation at: http://docs.opscode.com/ and knife-Oktawave repository: https://github.com/marek-siemdaj/knife-oktawave.