How to handle Python 3 Fabric exceptions with a Decorator

Python’s Fabric module is an easy and efficient way for task based automation.  I use it to automate the installation of VoIP phone systems on CentOS 6/7.  In a nut shell, Fabric executes shell commands over SSH.  It also can be used to automate local tasks.  The purpose of this article is to highlight the basic process of capturing Fabric exceptions(try/except) using a wrapper function called a decorator.  A few well placed decorators can save lot of time coding the same thing over and over(like capturing a specific error). 

Most of you in the know about Python/Fabric probably  will find my examples trivial, but I had to dig to find the Fabric exception environment variable.  I’m sure it’s somewhere on the Fabric site… but I gave up after 30 minutes.  So hopefully you will find this post useful either way!

If you need help installing Python3, pip3 and Fabric please refer to my previous post.

Goals of this Post:

  • create a simple Fabric function that creates a directory
  • create a Fabric exception
  • create Decorator for adding exception handling

Lets start with a basic fabfile.py: 



fabfile.py for Automating Git Repo Creation


Written by mattb in: | Tags: , , , , , ,

How to Install and Configure Basic Git Server on CentOS 6

Git has changed my life.  I’m not exaggerating.  I work with a lot of ‘one off’ scripts (BASH, PHP, and Python).  They are spread out among systems and developed from my workstation and(sometimes) laptop.  I spent 15 years keeping multiple versions and copies of the same scripts spread between systems.  Looking back it seems Crazy!

While I’ve known about Git for years, but I had no idea how badly I needed it until I interviewed for a contract and the interviewer repeatedly mentioned Git as a crucial part of their development process.  I admitted to him that I didn’t use it, but I would set it up myself and answer his questions in the next interview.  I installed it and set out to learn the centralized Git workflow(similar to SVN; one master setup).  There are other workflows and I recommend taking a look at this post if you are curious: https://www.atlassian.com/git/tutorials/comparing-workflows  

Goals of this Post:

  • Install  and configure basic Git for centralized workflow



Written by mattb in: Automation,Linux | Tags: , , , , ,

How to Install Windows 7 over a Network using Linux – PXE, DNSMasq, and Samba

As the age of the netbook arises; the ability to provision Operating Systems over the network becomes highly useful.  More and more these days, it’s less common to see CD/DVD ROM drives in laptops.  In my particular situation my laptop DVD-ROM drive failed.  This prompted me to embark on journey of sleepless nights, sifting through bad information and countless hours of ‘trial & error’ troubleshooting to make Windows 7 install from PXE boot server.

When I first started this project I had no idea what I was getting into or how difficult and poorly documented the PXE remote installation process is.  I imagined that I would use some kind RAM disk to load an ISO image of a Windows CD.  However, the process to boot an ISO image varies greatly between Operating Systems and Windows versions. So if you plan to install Windows XP or Linux using this tutorial…  you will fail.  This Tutorial is step by step for installing Windows 7(only) from a Fedora 10 provisioning server.  This tutorial assumes you have basic Linux, Windows, and Networking knowledge.

Goals of this post:

– Configure Linux Provisioning Server
– Prepare installation media and installation files
– Boot from PXE to Windows PE 2.0
– Install Windows 7 over Network