Tag Archives: vagrant

Setup StriderCD using Ansible

After several check on the web looking for ansible strider role, I created my own here: StriderCD Ansible Role

$ mkdir strider_test
$ cd strider_test
$ mkdir roles
$ ansible-galaxy --roles-path=./roles install cocoy.strider
- downloading role 'strider', owned by cocoy
- downloading role from https://github.com/cocoy/ansible-role-strider/archive/master.tar.gz
- extracting cocoy.strider to ./roles/cocoy.strider
- cocoy.strider was installed successfully
- adding dependency: Stouts.mongodb
- adding dependency: Stouts.nodejs
- downloading role 'mongodb', owned by Stouts
- downloading role from https://github.com/Stouts/Stouts.mongodb/archive/2.1.10.tar.gz
- extracting Stouts.mongodb to ./roles/Stouts.mongodb
- Stouts.mongodb was installed successfully
- downloading role 'nodejs', owned by Stouts
- downloading role from https://github.com/Stouts/Stouts.nodejs/archive/1.1.8.tar.gz
- extracting Stouts.nodejs to ./roles/Stouts.nodejs
- Stouts.nodejs was installed successfully
$ cp roles/cocoy.strider/tests/* .
$ ls
Vagrantfile ansible.cfg roles       test.yml

It’s now ready for vagrant up command.
Below are my screenshots, after using the same playbook on AWS instance.

strider_1

strider2

References:
https://fosterelli.co/creating-a-private-ci-with-strider.html
https://linuxmeerkat.wordpress.com/2014/12/11/jenkins-time-is-over/
http://doics.co/2014/10/15/strider-ci-without-the-overhead/

Vagrant: Productivity for both Developers and SysAdmins

Update Feb 22, 2012: I just found out another ‘cool’ tool at http://keminglabs.com/vagrant-ec2/ using vagrant for local image and with EC2 instance.

Vagrant is a productive tool in building and distributing virtual images for development.

1. Setup Virtualbox
2. Setup RVM
3. Install Ruby 1.9.2 inside RVM
4. Install Vagrant

$ gem install vagrant
$ vagrant box add base http://files.vagrantup.com/lucid32.box

5. Install chef (optional)

Once everything is set, a simple configuration on Vagrantfile can have the lines:

Vagrant::Config.run do |config|
  config.vm.box = "lucid32"
  config.vm.network "33.33.33.10"

end 

Start initializing and running our base image:

$ vagrant init base
$ vagrant up 
$ vagrant ssh

Now to start with chef-solo, you can download the getting started cookbooks:

Adding more cookbooks later, I need to generate the metadata.json.

$ cd /tmp
$ wget https://github.com/opscode/cookbooks/tarball/master -O cookbook-ops.tgz
$ tar -zxvf cookbook-ops.tgz
$ cd ops* 
$ knife cookbook metadata -a  -o ./ 

Generating metadata for 7-zip from /tmp/opscode-cookbooks-c156223/7-zip/metadata.rb
Generating metadata for activemq from /tmp/opscode-cookbooks-c156223/activemq/metadata.rb
Generating metadata for ant from /tmp/opscode-cookbooks-c156223/ant/metadata.rb
...

In my case, I copy only the nginx cookbook to vagrant cookbook directory, now the cookbook directory:

cookbooks/ 
    apache2      
	apt          
	nginx        
	vagrant_main

I need to edit the cookbooks/vagrant_main/recipes/default.rb for nginx:

require_recipe "apt"
require_recipe "nginx"

Now the new Vagrantfile will have the lines:

Vagrant::Config.run do |config|

  config.vm.box = "lucid32"
  config.vm.network "33.33.33.10"

  config.vm.provision :chef_solo do |chef|
     chef.log_level = "debug"
     chef.cookbooks_path = "cookbooks"
     chef.add_recipe "vagrant_main"
   end
end

And then we can start provisioning:

$ vagrant provision 

[default] Running provisioner: Vagrant::Provisioners::ChefSolo...
[default] Generating chef JSON and uploading...
[default] Running chef-solo...
[default] stdin: is not a tty
...

$ vagrant ssh
Linux lucid32 2.6.32-33-generic #70-Ubuntu SMP Thu Jul 7 21:09:46 UTC 2011 i686 GNU/Linux
Ubuntu 10.04.3 LTS

Welcome to Ubuntu!
 * Documentation:  https://help.ubuntu.com/
Last login: Fri Dec  2 01:27:30 2011 from 10.0.2.2
vagrant@lucid32:~$ sudo netstat -lp | grep www
tcp        0      0 *:www                   *:*                     LISTEN      739/nginx       
vagrant@lucid32:~$ 

Our nginx is running. 🙂 Let’s package our new nginx VM.

$ vagrant package --include Vagrantfile
[default] Attempting graceful shutdown of linux...
[default] Clearing any previously set forwarded ports...
[default] Cleaning previously set shared folders...
[default] Creating temporary directory for export...
[default] Exporting VM...
Progress: 0%Progress: 14%Progress: 28%Progress: 31%Progress: 34%Progress: 36%Progress: 46%Progress: 48%Progress: 57%Progress: 61%Progress: 68%Progress: 83%Progress: 86%Progress: 93%[default] Compressing package to: /Users/cocoy/vagrant/lucid32/package.box
[default] Packaging additional file: Vagrantfile

For distribution and restoring the new image:

$ vagrant box add newlucid package.box 
[vagrant] Downloading with Vagrant::Downloaders::File...
[vagrant] Copying box to temporary location...
[vagrant] Extracting box...
[vagrant] Verifying box...
[vagrant] Cleaning up downloaded box...

Note: We can edit the Vagrantfile to change the IP first if we need to.

$ vagrant up
[default] Importing base box 'newlucid'...
[default] The guest additions on this VM do not match the install version of
VirtualBox! This may cause things such as forwarded ports, shared
folders, and more to not work properly. If any of those things fail on
this machine, please update the guest additions and repackage the
box.
...

Distributing VM’s for developers to sync configs/software packages/files with production setup is easy.
Easy replication of servers via chef-solo recipes.
Testing integration with different parts of the system may it be database, cache servers, or web servers.

Good references about Vagrant:
Getting-the-most-out-of-Chef-with-Scalarium-and-vagrant
Vagrant-testing-testing-one-two
Vagrant Getting Started