The git Module

Length: 00:07:22

Lesson Summary:

When working with configuration management, we're often tasked with placing our work on version control, such as a Git application. Salt, of course, has a module for this, allowing us to use version control as well as add upstream and downstream repositories and manage our code on those.

Set Up Git on the Salt Master

Before we begin, create a GitHub (or GitLab) repository for the mysql formula; since this will be under your own account, you can give the repository any name you desire, but I suggest something descriptive. We'll be using la-salt-mysql below.

  1. Git is already installed on our Linux Academy cloud servers, so we won't need to do any prep work there. Instead, we want to go ahead and use Salt to set our default global configuration for our user user:

     $ sudo salt 'salt' git.config_set Elle global=True user=user
     $ sudo salt 'salt' git.config_set global=True user=user

    Note that we have to define the user we want to set the configurations for, lest it default to the minion's user, which is root. Additionally, if we do not include the global=True argument, we need to use the cwd parameter to define which directory path the user is being set under.

  2. To check that our configuration values are properly set, let's use the git.config_get function. Much like the function above, we'll need to define our user and the directory we're working with (or set global=True):

     $ sudo salt 'salt' git.config_get user=user global=True
     $ sudo salt 'salt' git.config_get user=user global=True

    You'll notice that if we leave out any of the above required arguments, we receive an error:

     $ sudo salt 'salt' git.config_get global=True
     ERROR: Minions returned with non-zero exit code
  3. Create our file_roots directory, where we'll be storing all our Salt states and formulas:

     $ sudo mkdir /srv/salt

    At this point, we want to make sure that we can easily add, remove, and edit files in this directory. Remember how we added a salt group earlier?

  4. Grant users in the salt group read/write/execute actions for the file_roots:

     $ sudo chgrp salt /srv/salt/
     $ sudo chmod 775 /srv/salt/
     $ sudo chmod g+s /srv/salt/
  5. For the permission changes to take effect, log out of the server, then log back in. You can also run bash to start a new session.

  6. Create a directory to store our future MySQL formula:

     $ mkdir /srv/salt/mysql
  7. Initialize the directory. Instead of doing this in the traditional way, we want to do this via execution module:

     $ sudo salt 'salt' git.init cwd=/srv/salt/mysql
  8. Add the remote origin:

     $ sudo salt 'salt' git.remote_set /srv/salt/mysql

From here, we can add, commit, pull and push changes, either through Salt or Git itself.

This lesson is only available to Linux Academy members.

Sign Up To View This Lesson
Or Log In

Looking For Team Training?

Learn More