Robin demonstrates provisioning an Unbuntu server with Vagrant and VirtualBox. Robin also describes other methods that are used to provision nodes.
- [Instructor] Welcome to class. Now that you have all the tools you need installed, I'm excited to have you here for this hands-on dive into Chef. Now to start off with, we'll want to create a working directory for the purposes of the course. Now I'm going to go ahead and create this in my desktop but you're welcome to put this wherever you'd like on your local machine. So I'll make a new directory here in my desktop called chef-essentials or chef dash essentials. From here, I am going to change into this directory from within my terminal.
Now again, I hope I'm clear here that you're going to be using the PowerShell or the terminal for this exercise. If you're unable to launch the PowerShell for example, you might try double-clicking the Chef Development Kit icon on your desktop. I'm going to change into the chef-essentials directory and from here I'll go ahead and get ready to set up my development environment. Now it's time to set up our Ubuntu workstation. To do this, you'll already verified that Vagrant and VirtualBox are installed.
So we're ready to go ahead and download the Ubuntu image we'll use for the class. Now you can use any image you'd like for this process. However, for the purposes of this class, we'll use a Vagrant or VirtualBox image that Chef maintains for testing purposes. The project is called Bento. So let's download a Bento box and spin it up. To do this, inside of my working directory, and again, you can check this by running pwd anywhere to make sure you're inside of the chef-essentials directory.
From here, I'll go ahead and run the vagrant box add command, and this is going to go ahead and download a particular image we can use. We'll download bento/ubuntu-14.04. Now the last thing to add here is a provider flag, - -provider, and we'll specify this as equal to virtualbox. This might take a moment, depending on the speed of your network.
Now that the image is available on your local system, we can go ahead and create the Vagrant file that Vagrant needs to go ahead and create our development environment. To do this, we'll use the vagrant init command. When we run vagrant init, we'll often want to provide an argument here to specify what type of machine to create. So we'll again tell it create a bento/ubuntu-14.0 system. This command should complete rather quickly and inside of your working directory, you should now see a Vagrant file.
Now this file is a stock file produced for this particular image. We may go ahead and edit this as we go throughout the class, so do pay attention as I go through the course videos to see if I'm modifying the Vagrant file at any point. The first thing we'll do is open this Vagrant file. Inside of it, you'll see a lot of different options that you could enable. We're going to scroll down until we find the section that allows us to created forwarded ports. This should be just about three-quarters of the way down the page, once you've opened your editor, and here you'll see config.vm.network.
Now this is commented out by default. I'm going to go ahead and have you uncomment this line. This will allow us to actually access what's being hosted inside of our virtual machine from our local machine, meaning in the virtual machine, if you're hosting something on port 80, it will be available on your local host's port 8080. Now you can go ahead and save this file. Now to apply our configuration that we've just made, we'll need to actually execute the creation of our virtual machine.
We have not yet configured the VM itself. We do this with the vagrant up command, and this will create your development environment from the specifics from within your Vagrant file. If you do make changes to your Vagrant file as we go through the class, make sure to run the vagrant reload command to apply that new configuration. For now, let's run vagrant up. Excellent, now that that process has completed, I'm going to go ahead and clear the screen, and free up some screen real estate.
Now we just went through and created our virtual machine and we're ready to log in to it. Now notice I am on my local machine here, and now I'm going to log in to the virtual machine with the vagrant ssh command. I must be within the directory where my Vagrant file is located for this to execute properly. Running this, you'll see that I'm actually going to be put now into the Vagrant shell. Essentially, I'm inside of the Ubuntu instance now, and you can notice this with the vagrant@vagrant preface to my shell here.
Now be careful. I'm going to be running commands in a number of places throughout this course. Please pay attention to where I'm running these commands so that you don't accidentally execute one on your local machine instead of inside of the virtual machine. Great. We'll be editing files throughout this class using a text editor of some sort. Inside of this virtual machine, you're welcome to install any text editor that fits your needs. We've got instructions inside of the setup documentation for installing your favorite text editor.
Throughout this class, you'll see me using Vim to actually go through and manipulate files, and now I'm going to install that with the sudo apt-get install command. I'll then enter the name of the package, vim, and I'll tack on -y to answer any prompts with yes. Great. Vim is already installed. It comes with Ubuntu. However, if you're going to utilize another text editor like nano, you'd simply enter in its name here. Great.
Now inside of this development environment, you should be set up to manipulate files. The last things we'll want to do is install the Chef Development Kit.
This intermediate-level course provides insights into the Chef architecture through practical examples and demos, including the deployment of a PHP application on top of a LAMP stack. Instructor Robin Beck walks through recipe development and the various prebuilt cookbooks available from the Chef community Supermarket, and reviews best practices for building wrapper cookbooks that allow you to access recipes from different cookbooks. He also shows how to work more efficiently with knife commands for managing clients, cookbooks, and data.
- Building a setup recipe
- Using cookbooks to organize recipes
- Using community recipes
- Uploading cookbooks
- Using the database cookbook
- Adding PHP to the mix
- Searching with knife
- Testing cookbooks with Kitchen