It’s now easier than ever to try out new tools and applications. Case in point: this week I’ve been working on a new build and deploy process for a customer. They are moving to a new workflow with continuous integration. So, I wanted to try out some specific features of Jenkins to see if these could solve the problem. If I was going to set it up manually what would I have had to do? Well first request a VM or create my own locally. Then I’d have picked and installed a Linux distro, configured SSH, logged in. Then I’d have read the documentation for Jenkins, followed an install guide. Maybe manually forwarded a port so that other VMs in my environment could reach it.
So what’s the easier way? We can use Vagrant to provision a virtual machine locally and we can have it trigger a config management tool to install Jenkins. Vagrant has good hooks into Puppet, Chef, Salt and Ansible. And there’s already a wealth of Cookbooks, formulas etc. to install things like Jenkins in a proper way.
For this example I’ve chosen Chef. Here’s what I actually did. I’ll even include the steps that you only need to do once:
1. Install Virtual Box (or VMWare Fusion if you like)
2. Install Vagrant.
3. Install the ChefDK. We need this because we want Chef’s dependency resolution tool Berkshelf. This will allow us to just specify the Jenkins cookbook and let Berkshelf find any cookbooks on which it depends.
4. Install some vagrant plugins: # First the Berkshelf plugin vagrant plugin install vagrant-berkshelf # Then the vagrant-cachier plugin. This one's optional but it'll save you a lot of time and bandwidth! vagrant plugin install vagrant-cachier
# First the Berkshelf plugin vagrant plugin install vagrant-berkshelf # Then the vagrant-cachier plugin. This one's optional but it'll save you a lot of time and bandwidth! vagrant plugin install vagrant-cachier
5. Now create a new folder and VagrantFile cd mkdir vagrant-jenkins cd vagrant-jenkins vagrant init ubuntu/trusty64 # Note you want an OS that the cookbook supports. However most will work with recent versions of Ubuntu.
cd mkdir vagrant-jenkins cd vagrant-jenkins vagrant init ubuntu/trusty64 # Note you want an OS that the cookbook supports. However most will work with recent versions of Ubuntu.
7. So we want to use Chef to setup Jenkins for us. So we need to create a Berksfile so that Berkshelf knows what cookbooks we want to download. touch Berksfile
touch Berksfile
And open it in your favourite editor. Here’s what we need to add: source 'https://supermarket.chef.io' cookbook "jenkins"
source 'https://supermarket.chef.io' cookbook "jenkins"
Pretty simple right! You could probably even have guessed the cookbook existed and not bothered to look it up. But just in case here it is.
8. Now we need to tell Vagrant to use the Chef provisioner and to run a recipe from this cookbook. Open up the Vagrantfile and add the following before the end of the Vagrant configure block. config.berkshelf.enabled = true config.vm.provision :chef_solo do |chef| chef.add_recipe "jenkins::master" end
config.berkshelf.enabled = true config.vm.provision :chef_solo do |chef| chef.add_recipe "jenkins::master" end
This tells Vagrant to use Berkshelf to resolve dependent cookbooks. It sets Chef solo as the provisioner and selects the Jenkins master recipe from the cookbook.
9. Expose the Jenkins port from the VM. Just to make life easier we’ll expose the jenkins port so that we can access it at http://localhost:8080. If you are using Virtual Box with the default network config and want to reach it from other VMs you’ll find it at http://10.0.2.2:8080. Just add the following to the Vagrantfile before the last end. config.vm.network "forwarded_port", guest: 8080, host: 8080
config.vm.network "forwarded_port", guest: 8080, host: 8080
10. Finally we can run: vagrant up
vagrant up
Now we just wait a few minutes or even less if you already have the vagrant box cached. When vagrant exits you should see lots of green text with the output from Chef solo and you should be able to access your new Jenkins instance at http://localhost:8080. Note that you could now use this method to bring up a test instance of nearly any software that there is already a cookbook for and you can start at step 5 in the future. Check out some popular ones on the chef supermarket.
We work with our clients to de-risk and accelerate their business goals realisation. Our approach is based on tailoring our services to fit your needs leveraging our portfolio of strategy, execution, innovation and service delivery offerings to help you reach your objectives
We’re always on the lookout for exceptional talent and people who share our values. Even as we continue to grow, we maintain a family environment with respect and teamwork core to our culture.
Companies can start deploying containerised workloads to Kubernetes In days not months, by leveraging Automation Logic’s Kubernetes Platform Accelerator.
Largest Irish-Founded Tech Employer Surpasses 3000 Employees Signing 15th and 16th Acquisition Deals Version 1, a leading digital transformation partner, is to acquire Automation Logic – for an undisclosed sum as part of its ambitious growth strategy for 2023 and beyond. The Automation Logic deal is subject to clearance by the National Security and Investment […]
Automation Logic were recognised as one of the UK’s best Workplaces again for the 5th year running! We also placed 29th in best workplaces for women. This highlights the great work that we are doing as a business, including all the wonderful work being put in by the employee-led DE&I groups. This award means so […]