Ansible changes the way you work. It helps shift from a world of manually executed tasks to automated and codified tasks. To do this you will incrementally build playbooks and will need to track changes in the files. You need source control for that.

Source control

Long gone are the days when you used shell histories and shared files to store your code. Source control lets you collaborate to store and audit your code.

Source control is a broad topic. Entire courses are dedicated to it. The good news is that you don’t need to understand the cavernous depths of source control. You just need enough information to become competent.

What is Git?

Git is a distributed source control system that:

  • enables you to work locally and independently.
  • supports collaboration, as you push your changes to the centralized server and pull changes contributed by your teammates to the codebase.

There are no more undo commands and v1 v2 files. You will no longer have to rely on those methods to track and roll back your code changes.

Git is a powerful tool as it provides a full historical audit of the codebase. On top of that, you can rollback.

You can use Git by either:

  • Cloning(copying) an existing repository.
  • Initializing a new repository.

The changes you make to the files are tracked using Git commands that allow you to:

  • add
  • commit
  • push

We will look at them in the next sections and lessons.

Create a GitHub account

Before you begin, you’ll have to create an account on GitHub. Do so by following these steps:

  1. Go to https://github.com/join
  2. Fill out the Create your account page with
    • Username
    • Email address
    • Password
  3. Complete the Verify your account puzzle
  4. Click Create Account

Once done, you are good to go. We will start by showing you how to create a Git Repository.

Creating and using a GitHub repository

Creating a repository in GitHub will initialize the repository and prepare it for use. We will be going through the process one step at a time.

Create a repository

  1. In the upper-right corner, click the + and then click New repository.
Create a repository
  1. Type a name for the repository and an optional description.
  1. Make the repository public.
  1. Check the box Initialize this repository with a README, then click Create repository. Optionally, select a license file and gitignore.

Making changes through GitHub web interface

One way to interact with your Git repository is to use GitHub’s web interface. Changes made directly on the server are the quickest way to make changes to your repository.

You will use the web interface in this section to create a file. To do so follow these steps:

  1. Click Add file and Create new file from the dropdown list.
  1. Name the file ad-hoc-ansible.md.
  1. Click inside the Edit new file box.
  2. Add a Markdown code block with an Ansible command.
Press + to interact
```
ansible localhost -m ping
```
  1. Scroll down to Commit new file, enter a commit message. Optionally, add an extended description. Then click Commit new file.

Using GitHub’s web interface is simple, quick, and easy, but it has some drawbacks. Directly modifying the code on the server can be a problem when working with others. It doesn’t take advantage of the distributed feature of Git.

In this lesson, we introduced the Git source control system, you created your first repository, and you made your first commit.

Get hands-on with 1300+ tech skills courses.