Infrastructure-as-a-Code-Git-Part-1

After our short introduction to IAC we shall start exploring some of the different tool that are mainly used in the IAC concept.
If you have missed the previous post you can read it here

The first tool I want to introduce is GIT (and I think is the most important one).

What is GIT

a lot of engineers (Me included) their first thought about Git is GitHub the public community Git is the place where many open source project are developed (and if you are a student, or buy a premium account you can have a private repository).
But Git is more than that, Git is a file version control, the file repository doesn’t have to be in Github, it can be a server, or it can be your local computer.

Why GIT

It seems like there is an agreement to use GIT as the main code repository (Like we as network engineers decided that RIP is dead, Rest In Peace).
After the first time you write your code or playbook you achieved some progress and you decide to keep working on the same file but things goes wrong and you can’t revert to the previous release because you didn’t create a copy before started to edit and you want to throw yourself outside of the window you get why Git is important, plus after learning GIT you can start contribute to open source project, it can be simple contribute even by reporting a bug, or add documentation.

How to use GIT

First thing first, you have to use some kind of Linux (MAC is also good) but I don’t think that Windows will work, if you are a Windows user, like me, install some kind of a Linux as a virtual-machine or on your local computer using some virtualization system (Virtualbox is an example), or on your virtual environment, containers etc’ as long as you have Linux. I’m using Ubuntu.

Dictionary

We need to be familiar with the language Git use, so we can speak in the same language:Git workflow:

Working directory – The development directory we are working in, we will make changes to the files in the working directory and we will push them into staging.

Staging – After we achieved some changes we are happy with but we didn’t finish working but we want to save our progress we can push the files into staging, this is not the official release but we have achieved some progress.

Repository – Contain the production files, the official releases of our files.

Branches – There is the master branch which is the production release, and when you experiment with a new feature for the project you create a branch for it, and later on merge it into the master.

Installing GIT:

At my Ubuntu it is really simple, apt install git, and you are good to go

Git for the lone wolf

even if you work on a project alone you can leverage Git, you don’t have to install a server, and you can use all the Git benefits without the teamwork.

First we have to tell Git who we are (don’t be rude), so configure Git with your information:
git config –global user.email “omershtivi1989@gmail.com”
git config –global user.name “Omer Shtivi”

So let’s start with a simple example, we want to keep track of the VLANs,
Open the terminal where you want the local repository to be and use the following command:git init

When committing a change from staging to the Repository each commit is added a SHA value in order to allow you to revert back to previous releases (or review previous file).
To check the SHA value:git log

Next post hopefully we will go over installing a Git server, and how to do teamwork, thanks for reading!

About Omer Shtivi

Omer Shtivi, CCIE #51906, has over nine years in the network industry, working for an Israeli reseller in the last six years. Omer has done projects for large enterprises, in many technologies using various vendors.
Lately he is exploring automation and orchestration technologies.

You can reach Omer:
omershtivi1989@gmail.com
https://www.linkedin.com/in/omershtivi/