How to use Vagrant with Outscale Cloud

Vagrant

What is Vagrant ?

Vagrant is a tool for building complete development environments. With an easy-to-use workflow and focus on automation, Vagrant lowers development environment setup time, increases development/production parity, and makes the "works on my machine" excuse a relic of the past.

—Vagrant website (http://www.vagrantup.com/about.html)

Vagrant installation

You can download and install Vagrant by following this link : https://www.vagrantup.com/downloads.html

To install aws plugin into Vagrant use the command line :

$ vagrant plugin install vagrant-aws

Now the ec2 plugin is installed and you need a Vagrant box to use it. With ec2 provider you don't need a linux box as for VirtualBox, just a metadata box.

You can download the Outscale box by downloading the box and installing it :

$ wget -O /tmp/ows.box https://github.com/bzhtux/my-vagrant/raw/master/outscale.box

Install Outscale box with Vagrant command line :

$ vagrant box add /tmp/ows.box --name ows

When you install a new box, a new directory is created in ~/.vagrant.d/boxes/ . So take a look at ~/.vagrant.d/boxes/ows/0/aws/ :

$ ls -1 ~/.vagrant.d/boxes/ows/0/aws/
Vagrantfile
metadata.json
$ cat ~/.vagrant.d/boxes/ows/0/aws/Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :

vagrant.configure("2") do |config|
  config.vm.provider :aws do |aws|
    aws.ami = "ami-37f43c43"
  end
end
$ cat ~/.vagrant.d/boxes/ows/0/aws/metadata.json
{
        "provider": "aws"
}

The Vagrantfile contains some default values like ami and other stuff you need by default, and a metadata.json file only containing the Vagrant provider.

Check th ec2 plugin is enabled :

$ vagrant box list
ows (aws, 0)

That means your Vagrant installation is fully functional with the ec2 plugin.

Oustcale Cloud

Outscale Cloud plateform provides an API like AWS, with full compatibility with the Amazon Web Services. To deploy VMs over Outscale Cloud you'll need at least :

* access key
* secret key
* endpoint url

Both of access key and secret key are your own and endpoint url is the same for eu-west-1 region :

* endpoint_url = https://api.outscale.com

Oustcale provides as well as AWS ressources listed below :

* AMI
* security groups
* EIP
* EBS
* Snapshots (ec2 and EBS)
* keypair
* and many others you probably don't need here

You will need some of these ressources to deploy virtual instances with Vagrant over Oustcale Cloud.

Vagrant over Outscale

Vagrant uses a single file for its configuration : Vagrantfile .

Here is a sample configuration file :

# -*- mode: ruby -*-
 # vi: set ft=ruby :

 # Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
 VAGRANTFILE_API_VERSION = "2"

 vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
   config.vm.box = "precise64-byaf"
   config.vm.network "forwarded_port", id: "ssh", guest: 22, host: 2222, disabled: true
   config.vm.host_name = "my-yaf"
   config.vm.network :private_network, ip: "192.168.33.251"
   config.vm.network "forwarded_port", guest: 22, host: 2221, auto_correct: true
   config.vm.provider "virtualbox" do |v|
     v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
     v.customize ["modifyvm", :id, "--memory", 2048]
   end
 end

In this sample, Virtualbox is used as provider (that's the default behaviour).

Here is a sample configuration file using aws (over Outscale) as provider :

# -*- mode: ruby -*-
# vi: set ft=ruby :

# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"

vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "ows"

  config.vm.host_name = "Vagrant.tinappd.dev"

  config.vm.provider "aws" do |aws, override|
    aws.access_key_id = "--REMOVED--"
    aws.secret_access_key = "--REMOVED--"
    aws.endpoint = "https://api.outscale.com/"
    aws.keypair_name = "ows-demo-prd"
    aws.region = "eu-west-1"
    aws.security_groups = ["default","web"]
    aws.instance_type = "m1.large"
    aws.ebs_optimized = 'True'

    aws.ami = "ami-7c5fa20e"
    aws.tags = {
        Name: 'Vagrant',
        Env: 'dev'
    }


    override.ssh.username = "root"
    override.ssh.private_key_path = "/Users/bzhtux/.ssh/ows-demo-prd.pem"
  end

end

config.vm.box : "ows" is your Outscale box

config.vm.host_name : this is an arbitrary hostname

aws.access_key_id : your Outscale access_key

aws.secret_Access_key : your Outscale secret_key

aws.endpoint : use Outscale API to deploy your VMs

aws.keypair_name : your favorite Outscale keypair

aws.region : eu-west-1 to deploy in France

aws.security_groups : Your Outscale security groups (here default let me log in with ssh and web open 80 port)

aws.instance_type : Choose your Outscale instance type

aws.ebs_optimized : use IOPS

aws.ami : Your favorite AMI or you can choose a public one

aws.tags : Set your tags here

override.ssh_username : in order to vagrant works over Outscale cloud override ssh.username with root account.

override.ssh.private_key_path : this one should be the same as aws.keypair_name

Then you can see the provider section, filled with the Outscale ressources values.

Then to launch a virtual instance :

$ vagrant up --provider aws

Enjoy your first Vagrant VM over Outscale Cloud :)

Some samples are available following this link : https://github.com/bzhtux/my-Vagrant

Extras

You can also provide a provisioner like puppet or ansible or what you want if it's supported.

To use provisionning with Vagrant, you should use :

  vm.provision "ansible" do |ansible|
    ansible.playbook = "ansible/common.yml"
    ansible.limit = 'all'
    #ansible.verbose = "vvvv"
    ansible.groups = {
      "web" => ["www-1","www-2"],
      "database" => ["bdd"]
    }
  end
end

and replace ansible with the provisioner you choosed.

Ansible is used to provision all my virtual instances (www-1, www-2 and dbb).

Ansible documentation is not cover by this post, a new one will be dedicated to Ansible.

Comments !