This content is part of the Essential Guide: Bookmark this expansive guide to DevOps for Windows

Boost DevOps cred with script management in Git version control

DevOps teams use configuration management to automate patches and provisioning. They use version control to increase collaboration and change control. Learn how to combine the two.

You need a version control system to get the most out of IT automation. With a little work, DevOps and systems administrators can learn Git.

With version control for script management, you won't simply lose a script through a hardware failure or disorganization. Version control lets programmers check out and lock scripts, so others cannot change them at the same time.

And it keeps track of different versions. So, if version n of an automated process does not work, simply roll back to n-1 and continue experimenting. These features enable DevOps teams to rely heavily on IT automation without risky deploys or diminished change control.

Version control tools

Two popular Version control options are Atlassian Bitbucket and GitHub, which Microsoft is in the process of acquiring. GitHub has the larger number of users by far, but both products are free for users willing to store code publicly, meaning anyone can read it.

Private storage comes at a price, but could be the right choice for configuration management scripts, such as a provisioning sequence that reveals the security strategy for your company's IT infrastructure. Bitbucket is a lower-cost alternative to GitHub for private code repositories. Bitbucket offers a free private repository for up to five users, whereas GitHub's only free private option is for students.

Git, an open source version control protocol, is the main technology to push software to and from public repositories. GitHub, as the name implies, relies on Git, while Bitbucket uses either Git or competing technology Mercurial.

This script management tutorial uses Atlassian Bitbucket, relying on Git, to store Salt configuration setups. The Salt configuration management tool -- and an enterprise version of SaltStack from the eponymous vendor -- is in place at IT and DevOps shops to automate VM provisioning, patch deployment and other operations tasks. Similar tools include Chef, Puppet and Ansible, and their users can also call upon version control for script management.

Store Salt scripts in Bitbucket

Salt scripts are stored by default in /srv/salt. In this example, I can list the three files seen in the output below:

_grains  kubernetes.sls  redis.sls  top.sls  webserver.sls

Author's note: In this tutorial, we will store the kubernetes, redis and webserver configuration scripts in Bitbucket. We do not include the grains folder for Salt to interface with managed machines or the top file, which tracks roles and groupings of managed machines.

Use Windows Installer, apt, Homebrew or yum to install Git, and create an account on Create a new repository, which is a folder where Git stores the Salt configuration code files.

In Bitbucket, name the repository appropriately for these IT automation scripts, such as salt or saltstack. Select Git instead of Mercurial. A README -- an option for documentation -- is a topic for another day. Do not include one here.

In Figure 1, Bitbucket has created the remote repository and provided the address to access it: https://(your user name) username)/salt.git

Bitbucket repository
Figure 1. A repository named salt is now available for configuration script management.

The Salt scripts are stored in a folder /src/salt, owned by root, so use sudo for each of the following commands. Git will update files locally to keep track of what you change.

Make an empty Git repository with the sudo git init command.

Tell Git where the remote repository is stored -- swap my user ID werowe with your own -- with the following command:

sudo git remote add origin https://[email protected]/werowe/saltstack.git

Add any desired files to the local copy of the repository, with a string of git add commands:

sudo git add kubernetes.sls
sudo git add redis.sls
sudo git add webserver.sls

A Git commit saves the changes made locally, in preparation to push them to the remote, cloud-hosted repository. Each commit should carry a comment, such as "first commit," to document what changes took place. Comments help the person or team that approves changes to know your intent. Bitbucket has an approval process, as well.

Manage Git with Salt

Salt also can work with objects in Git directly, with the object salt.states.git. You could use that for different purposes, like clone. Cloning a repository means downloading it without checking it out. You might do that, for example, when you need to pull down source code in order to compile it.

At this point, use the following: sudo git commit -m "first commit"

Git will echo that it adds the three files (see Figure 2).

Git commit
Figure 2. Git adds three files -- kubernetes, redis and web server -- with 21 insertions.

To upload the changes into the central repository of code, use the push command: sudo git push origin master

It will prompt for a password, then respond (see Figure 3).

Git push
Figure 3. Git performs the code push to the centralized repository.

Click on the branch in Bitbucket -- in this case, it is SaltStack -- to see that the three files uploaded (see Figure 4).

Bitbucket repository branch.
Figure 4. Three files committed and pushed to the central repository now appear in Bitbucket, with the size, timing and comments available.

IT operations teams can collaborate on these scripts now that they are managed in a centralized repository.

This example of script management is specifically for a configuration management tool, but it's easy to extrapolate other ways to use version control to bring order and visibility to IT operations tasks, such as deployment scripts, storage management and business process automation.

Dig Deeper on Systems automation and orchestration

Software Quality
App Architecture
Cloud Computing
Data Center