The Salt File Server

Length: 00:08:50

Lesson Summary:

To work with files, Salt includes a stateless ZeroMQ file server that lets us send files to the minions from the master.

Files should be saved in our file_roots (/srv/salt/), generally within the directory of the formula they are being used for. However, files not associated with any formulas or states can still be saved and shared.

Manage the MariaDB Conf

For CentOS servers, the MariaDB configuration files are located within the /etc/my.cnf.d directory, with a primary configuration file located at /etc/my.cnf. Since we're working on setting up MariaDB as a server, not a client, we'll be working to make sure our /etc/my.cnf.d/server/server.cnf file is managed by Salt.

  1. Without our mysql directory, create a folder to store our configuration files:

     $ cd /srv/salt/mysql
     $ mkdir files
     $ cd files
    
  2. Pull in the configuration file:

     $ curl -O https://raw.githubusercontent.com/linuxacademy/content-ssce-files/master/server.cnf
    
  3. Open the file. When managing a file in Salt, it is best practice to place a comment at the top of the file informing anyone using the server that the file is managed by Salt, and should not be edited outside of configuration management:

     $ $EDITOR server.cnf
    
     # The file is managed by Salt.
    

    If needed, you can get more specific in this comment. You can make a note not to edit the file at all if you have any eager people working on the database or otherwise need to provide more information.

  4. Save and exit the file.

  5. We can now create another state, this time for adding this file to our CentOS 7 database minion. Let's drop back down into our MySQL formula folder, then create a config.sls file:

     $ cd ..
     $ $EDITOR config.sls
    
  6. From here, we want to set our state's name declaration. Remember, we want this to be specific so that anyone running these states later can read the output:

     mysql_server-config:
    
  7. Next, to work with files, we need to use the file state module. Specifically, we want to use the file.managed function, which allows us to define a file, its source, its location on the minion, and more:

     mysql_server_config:
       file.managed:
    
  8. We now need to set our parameters for our managed file. The two parameters we need to include are the name parameter, which will define the location of the file on the minion, and the source parameter, which defines where on the master the file is located. Additional arguments, such as setting the user or group for the file and setting a source hash are also available. All arguments can be found via the sys.state_argspec function.

    Let's add our name and source:

     mysql_server_config:
       file.managed:
         - name: /etc/my.conf.d/server.cnf
         - source: salt://mysql/files/server.cnf
    
  9. Save and exit.

  10. Finally, let's ensure our state doesn't contain any errors by running a test state run:

    $ sudo salt 'minion2' state.sls mysql.config test=true
    


This lesson is only available to Linux Academy members.

Sign Up To View This Lesson
Or Log In

Looking For Team Training?

Learn More