Category Archives: Python

Infrastructure as Code on GCP

Recently I was involved in a professional services engagement along side Google Professional Services.  In that engagement I got to see first hand how Google implements solutions on GCP, including the deployment of a high-performance compute platform proof of concept.  One of the most interesting aspects of that engagement was how the Google team implemented the entire solution using the Infrastructure as Code IaC) paradigm.  At no point in the development of the POC did the team configure something directly in the console.  This allowed them to build and tear-down the environment as needed, and once complete, they could turn over a running POC to the customer for further development and implementation. So taking direction from how Google does things, I decided to do the same for the Ansible host configuration in the previous post.

My goal was to automate the implementation of the Ansible host using GCP Deployment manager so that in the future when I want to run Ansible tests, I can deploy the environment within 10 minutes and remove it instantly when I am done.  To keep the entire environment ephemeral, all of the configuration was put into GitHub.  Future Ansible playbooks will also be placed in GitHub so that all I need to do is spin up the environment, clone the latest playbook I am working on and continue where I left off.

You can see the full configuration on GitHub here:

Ansible Core on GCP with Deployment Manager

In building the configuration I relied on the code that the Google PS team used as an example along with other examples from the Google documentation and from StackOverflow.  Some of the python scripting is my own since it is fairly basic and unique to this project. 

veripy Lab Setup

The lab I planned on using for this project centered around a Ubuntu desktop client installed as a VM under VMWare player.   In order to provide IPv6 connectivity, I used GNS3 with a virtual Cisco router running IOS 12.4(21).  I used a evaluation version of Windows8 as the system to run the tests against.  Windows8, even though it is an evaluation version which I got as a beta version seems to keep itself up to date, so I figure it should pass with flying colors.  To monitor much of the testing I planned on using Etherreal which is installed natively on my Wondows7 host workstation.  The following diagram should make everything clear:

Installing veripy took longer than expected due to my lack of knowledge about Python.  Python is an interpreted programming language which is supported by default under Ubuntu.  I have never installed or used a Python based application and so learned a lot about how Python works during this installation, mostly because I have trouble following directions.  veripy required a couple of other Python based applications to make it work, the most important of which is Scapy, the program used to generate the IPv6 packets (especially the bad ones, wrong version number, etc.).  Most Python modules are installed like normal applications using the “appget” command.  Modules are installed under the Python directory.

I started by downloading the veripy-1.0.1.tar.gz archive and unpacking into a subdirectory called Apps (/home/cbroccoli/Apps).  Since veripy does not install as a standard Python module (see how Scapy was installed below to see that), I had to add the location of the base veripy files to the PYTHONPATH environment variable.  This was done by adding the following line to the /etc/environment file:

PYTHONPATH="/home/cbroccoli/Apps/veripy"

Adding the variable to the /etc/environment file ensures that the environment variable is persistent across terminal windows, reboots, etc.  To confirm that the change worked run the following command:

$ printenv PYTHONPATH

With this done, I installed the applications which are required for scapy:

$ sudo apt-get install tcpdump graphviz imagemagick python-gnuplot 
python-crypto python-pyx

Finally, I downloaded and installed Scapy:

$ cd /home/cbroccoli/Downloads
 $ wget scapy.net
 $ unzip scapy-latest.zip
 $ cd scapy-2.*
 $ sudo python setup.py install

Now I was ready to run the tests.