Vagrant is a great tool to build and distribute development environments. Vagrant allows us to keep development environment configuration same on various machines in order to avoid issues like “It works on my machine !”. If you haven’t started with vagrant please go though the getting started guide of vagrant. It’s very easy to setup. I have written up a post with detailed screenshots here
Ansible: Vagrant Provisioner
Vagrant can be provisioned with various provisioners. We can use basic shell provisioner or Chef or Puppet to provision vagrant boxes. My choice is Ansible , there are many reasons to choose Ansible but here are few
- Ansible is very simple to configure
- Ansible has many simple and easy playbooks
- Ansible has predefined roles which we can use directly. It reduces lots of scripting.
- Ansible is cross platform
- Ansible output is very readable as compared to Shell and Chef.
Android Appium with Ruby
Now that, we will provision Appium Android and Ruby environment with Ansible on a vagrant box. Appium is a mobile test automation framework. In order to set it up, we need following technology stack
- Ruby and RVM
- Android SDK
On Mac OSX, you can install Ansible with Brew
$ brew install ansible
Let’s create a project directory and Vagrantfile inside the project
$ mkdir vagrant-appium-ansible
$ cd vagrant-appium-ansible
$ vim Vagrantfile
Add details to Vagrantfile which looks like this:
# -*- 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 = "ubuntu/trusty64"
config.vm.hostname = "appium-ansible"
config.vm.provider "virtualbox" do |vb|
vb.customize ['modifyvm', :id, '--usb', 'on']
vb.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/vagrant", "1"]
vb.customize ['usbfilter', 'add', '0', '--target', :id, '--name', 'Galaxy Nexus', '--vendorid', '0x04e8']
config.vm.provision :ansible do |ansible|
ansible.playbook = "playbook.yml"
Now Let’s understand what’s in the vagrant file.
We have specifiled box name as ‘ubuntu/trusty64’ which is a ubuntu desktop 14.04 also we have provided host name as ‘appium-ansible’
- USB and Vagrant Box
Second part is all about USB connection with Vagrant Box. We need to specify vendorID and ProductID of the attached device in order to recognise the device by the box.
In the final part of the Vagrantfile, we have specified config file ‘playbook.yml’ for ansible.
Install Required packages
Now we will configure all required debian packages for ruby, appium and nodejs
Install Android and RVM
This part of the playbook file install Android SDK and Ruby/RVM.
We also need out android.rules file which will be then copied to ‘/etc/udev/rule.d/51-android.rules’
Sample file can be found on GitHub here
Now that, we are all set to boot our vagrant machine. We can now run command
$ vagrant up
This will boot new ubuntu box with specified host name.
Now, our machine is booted and ready. It will now start provisioning from our playbook.
Now that our machine will first install all the required packaged and then carry on installing RVM and Ruby
Ansible will then install Android and Appium as follows
Now that we have our ubuntu machine fully provisioned with Ansible tasks. Now lets ssh into the machine and check all the things installed correctly
We can see that Android SDK and RVM and NodeJS has been installed correctly.
Run Appium Server
Now that, we have ‘node_modules’ directory with appium installed. We can launch appium server like this
$ nodejs node_modules/appium/bin/appium.js
We can now make use of the Appium server to launch our mobile automated scenarios.
We can build and distribute vagrant development environments fully provisioned with Ansible for Appium mobile test automation. This can save lot of time in settting up development environments on every machine.
You can find source code on GitHub ‘vagrant-ansible-appium‘