Learn how to create an environment where your production code will be deployed to using Vagrant and VirtualBox. This setup will be used for the rest of the course demos.
- [Instructor] Before I jump into any exercises, I just want to take a moment to talk about my development environment you'll see me using in this class. Now in particular, I'll be using Vagrant and VirtualBox to manage machines that I want to configure with Chef. However, there are many ways to go about doing this. You could for example, use a cloud provider like Amazon Web Services to actually create the machines that you'll configure with Chef. In my case, I'm going to use Vagrant and VirtualBox because they're free and easy to get started with.
So to use these tools, you should understand that I've installed them on my machine, and that prepares me to actually go through and launch a virtual machine that I can configure. To to any of this, if you're going to follow along, I recommend checking the minimum requirements for both of these tools. For example, you'll need to make sure that your BIOS supports hardware virtualization. After making sure that your system meets these requirements, you can then go through and attempt to install these tools.
You'll also want to make sure that you have an SSH client available for communicating with your instances. Now on most Linux-based systems, you could use the Terminal. So if you're on a Mac or some other Linux flavor, the Terminal should suit your needs. On Windows machines, you're welcome to use something like PuTTY to connect to the instances, or if you've installed the Chef development kit, it also contains Git Bash, an SSH client. Now I'm going to recommend that you install these tools if you want to follow along.
However, understand that VirtualBox, Vagrant, and whatever SSH client you may be using are not Chef products. If you run into issues with these programs, I recommend checking out some of the attached documentation, such as Vagrant issues or the VirtualBox Bugtracker to make sure there aren't any active bugs in the latest versions you're using. With all that in mind, you're welcome to install VirtualBox. You can do this directly from Oracle's website or on Windows systems, you might consider using the Chocolately installer.
You can verify your installation by running VBoxManage --version. And it should report back the version without any errors. Similarly, for installing Vagrant, you can download it directly from HashiCorp's website or again on Windows systems, you might consider using the Chocolately package manager to install it. Once you've successfully ran through the installation, inside of your PowerShell or Terminal windows, again you should now be able to run vagrant --version and it shouldn't produce any errors.
If you can't get back the versions of these tools for any reason, you might check your system path and see if it includes Vagrant and VirtualBox. Once you've gone through these steps, you'll then need to actually download the base box that we'll use to actually spin up a machine that we'll configure with Chef. With Vagrant, we have the concept of boxes and we'll need to add the actual operating system we're interested in using. I'm going to be provisioning CentOS 7.2 instances in this class.
So I'll run the vagrant box add bento/centos-7.2 and I'll add the --provider=virtualbox flag there to insure we grab the right box. After you've run this command successfully, we'll be able to launch our new CentOS 7 instance. To do this, you'll first run vagrant init bento/centos-7.2. This will create what's called a Vagrantfile used for actually provisioning the machine.
Once the Vagrantfile has been created in this directory, I can run vagrant up, and it will spin up this virtual machine. I'll then finally be able to login to it with the vagrant ssh command. In this class, you'll see me targeting a specific machine, such as vagrant ssh machine one, and that will log me into the instance. Finally, I can install the Chef development kit inside of this virtual machine, if you prefer to follow along with some of the exercises I'll be demonstrating.
Again, I'll be working directly inside that virtual machine, for the beginning portion of the class. You might also look into some common commands that will be used. For example, I'll be using a text editor quite often, and you'll see me using VIM. You're welcome to use any other text editor as well, such as Emacs or Nano. You'll then want to also understand how to manage your Vagrant instance. There are common set of commands that you can use, and you can find them quite easily, but you might be aware of the vagrant ssh-config command, in particular.
That'll display some connection details that I'll be using throughout the class. If you wish to shut down your machine, you can run vagrant suspend to save its state. And with the vagrant destroy --force command, we'll actually kill any running virtual machines. Once you've followed these setup instructions and you feel confident that you've got it all in place, feel free to proceed on with the videos. And check out the class exercises.
- Configuration management
- Using Chef
- Installing the Chef development kit (ChefDK)
- Provisioning a CentOS instance
- Using recipes and the Apache cookbook
- Working with nodes and node objects
- Using templates and embedded Ruby
- Hosting a Chef server
- Provisioning nodes with AWS
- Testing deployments with Kitchen
- Exploring the Chef Supermarket
- Resolving dependencies with Berkshelf
- Working with server roles, environments, and data bags