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.
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
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
$ sudo salt 'salt' git.config_set user.name Elle global=True user=user $ sudo salt 'salt' git.config_set user.email email@example.com 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.
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
$ sudo salt 'salt' git.config_get user.name user=user global=True $ sudo salt 'salt' git.config_get user.email 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 user.email global=True salt: ERROR: Minions returned with non-zero exit code
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?
Grant users in the
salt group read/write/execute actions for the
$ sudo chgrp salt /srv/salt/ $ sudo chmod 775 /srv/salt/ $ sudo chmod g+s /srv/salt/
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.
Create a directory to store our future MySQL formula:
$ mkdir /srv/salt/mysql
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
Add the remote origin:
$ sudo salt 'salt' git.remote_set /srv/salt/mysql https://github.com/elle-la/la-salt-mysql.git
From here, we can
push changes, either through Salt or Git itself.