VMworld Europe Hackathon: Preparation

We are getting closer to VMworld Europe and the Hackathon that goes with it. For team Automation for All, this means we are getting prepared to have a lot of fun on Monday.

The goal of this post is to give an overview of the requirements of working with Ansible and how to properly setup your environment.

As a first tip, the best thing to do as preparation, is to look at all the available VMware focused standard modules in Ansible. A full list can be found here. The vsphere_  modules are being deprecated and should not be used.

Environment requirements

Nice-to-have

Setting up your environment

Below are a couple of guides for use with Mac OS X environments and Linux environments. Go through them and see if you think this is something you feel comfortable with. It will setup a virtual Python development environment, use the 2.4 Ansible release (soon to be released) and clone the github repository which will be used for the Hackathon work.

These guides are general guides and some changes might be needed in your particular environment. Especially if you use another Shell instead of Bash.

Setting up Python development environments

Linux

For Linux, you should use your distributions package manager to make sure python and the packages are all installed. The following section assumes a fresh installed CentOS 7 environment, as an example.

It will install the necessary components, setup a Python virtual environment, clone the github repositories of both Ansible and the team’s repository to start working.

# Install the correct packages
sudo yum install -y python-setuptools python-devel openssl-devel libffi-devel git gcc vim
sudo easy_install pip
sudo pip install virtualenv virtualenvwrapper

# Setting up a virtual environment
echo "export WORKON_HOME=\$HOME/.virtualenvs" >> ~/.bash_rc
echo "source /usr/bin/virtualenvwrapper.sh" >> ~/.bash_rc
source ~/.bash_rc
mkvirtualenv ansible-dev
pip install --upgrade pyvmomi ansible

# Testing Ansible version
ansible --version

# Getting 2.4 Ansible
# Make sure you have a proper SSH key in GitHub to access the Ansible repository
git clone [email protected]:ansible/ansible.git
cd ansible
git checkout stable-2.4
source hacking/env-setup
ansible --version

# Getting the development project loaded
cd ..
git clone [email protected]:pdellaert/automation-for-all.git
cd automation-for-all

This is also demonstrated in thefollowing asciinema recording.

For other distributions, a similar process can be found with some Google FU ;).

Mac OS X

On Mac OS X, it is typically advised to install Homebrew and the Python version in Homebrew, there are several advantages of doing so as the Python version on Mac OS X has it’s downsides and changes which are not standard.

The following list of commands are targeted towards a Mac OS X Sierra environment. And go through the process of setting up Homebrew, using pip to install the virtual environment system and setting up a virtual environment to work on with Ansible.

It will also install hub, a wrapper for git with some more advanced usage for Github.

# Installing Homebrew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

# Installing and upgrading python and pip
brew install python
sudo pip install --upgrade pip
sudo pip install virtualenv virtualenvwrapper
brew install hub

# Setting up a virtual environment
echo "export WORKON_HOME=\$HOME/.virtualenvs" >> ~/.bash_profile
echo "source /usr/bin/virtualenvwrapper.sh" >> ~/.bash_profile
echo "alias git=hub" >> ~/.bash_profile
source ~/.bash_profile
mkvirtualenv ansible-dev
pip install --upgrade pyvmomi ansible

# Testing Ansible version
ansible --version

# Getting 2.4 Ansible
# Make sure you have a proper SSH key in GitHub to access the Ansible repository
git clone [email protected]:ansible/ansible.git
cd ansible
git checkout stable-2.4
source hacking/env-setup
ansible --version

# Getting the development project loaded
cd ..
git clone [email protected]:pdellaert/automation-for-all.git
cd automation-for-all

Using the environment after you opened a new terminal

If you start a new terminal, by default it will not go into the proper environment we have set up in the above section. To solve this, you can follow these commands:

# Reactivate the virtual environment
workon ansible-dev

# Reactivate the 2.4 release candidate (assuming you cloned the ansible repository in your home folder)
source ~/ansible/hacking/env-setup

Hackathon

It looks like the schedule of the Hackathon will allow us to work for 3 hours. Looking forward to it!