When IT teams manage environments at a large scale, even the most minor change can have major consequences. Version...
control plays a critical role in IT infrastructure configuration stability and accountability.
Version control, while common in developer toolkits, is a new addition for many IT admins. The Git version control system, which is open source and instituted across many types of IT organizations, enables users to manage not only source code, but all manner of configuration files. Users save files and changes into Git with commits. Therefore, IT admins can write configuration as code, which means they control IT infrastructure via a template, such as YAML, with scripted provisioning steps. Configuration as code enforces standardization in a large environment and helps prevent issues across complex setups.
Git also enables developers to easily track changes across their source code, wherein they can roll back, revert and create new versions -- or branches -- in parallel. Basic Git commands and concepts are easy to learn, and using Git is the same across different systems.
Download and install the appropriate version from Git's website; the specifics of an installation might depend on the particular OS.
This demo of the Git version control system is based on the Windows root directory. Create a folder called source in the root directory for the source code, and enter it.
Open a command prompt, and initialize Git by typing git init in the source folder (Figure 1).
Use a basic configuration string to specify repository ownership. Ownership information is used for commits. Configure Git using:
git config –global user.email "firstname.lastname@example.org"
git config –global user.name "My Name"
Basic Git commands
You can now add files into the system and subject them to version control via the git add command. If configuration files are not added to Git, they are considered uncontrolled and, therefore, should be ignored. To add a single file -- that has already been created -- use:
git add myfile.txt
Alternatively, wildcards -- for example, git add * -- enable the user to add all the files that are in the source folder. However, if you don't add the files after changes are made, Git will not recognize the new version and will thus only display the old version. Step one is to save the file, but the vital second step is to add that updated file to Git.
The files are now in the system, but to commit the files -- i.e., create a point-in-time copy -- use the git commit -m function. The commit requires options such as comments. Note in Figure 3 the string 8e93636, which is the commit ID. This unique identifier enables Git users to roll back to a previous version of a file at any point in time.
The Git version control system now recognizes and manages the file. To add a second file, use the following commands:
git add secondfile.txt
git commit -m "Second source code file added"
Return to the first file, and edit it to add a second line, creating a new version. This simple example illustrates how an IT administrator would update, for example, network configuration settings for a deployed VM or other configuration-as-code files.
Re-add the file to Git with git add *, and commit it with a comment -- git commit -m "Added second line" -- to provide information about what changed.
Git displays information on the number of changes made to a given file. This feature enables a user to compare, contrast and revert code versions as necessary. Use the command git log to view the history of file changes and commits.
The git show command (Figure 6) displays the differences between file versions.
To revert a file, check out the file with the Git checkout [commitid] filename command.
The contents of the file will revert any changes after that file version, as if it never existed. Use the command with caution, and maintain a careful system of backups.
For a single user, the version control system is simple enough, once you master basic Git commands and concepts. However, for a team of users, a centralized, multiuser platform coordinates and manages that system more efficiently. Many version control tools are marketed to enterprises, including GitHub, Microsoft Team Foundation Version Control, Atlassian Bitbucket and Perforce. Some vendor products are based on the Git open source technology, while others use a different approach.
IT admins interested in using Git for configuration as code but deterred by the command-line interface should investigate GUI-based tools, but only once they have a solid understanding of the underlying concepts of version control.
Unsurprisingly, Git itself is version-controlled and offers a comprehensive guidebook.