Book Image

Salt Cookbook

By : Anirban Saha
Book Image

Salt Cookbook

By: Anirban Saha

Overview of this book

Table of Contents (18 chapters)
Salt Cookbook
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Using MySQL databases


In this recipe, you will learn how to create and remove databases in MySQL. You will also learn how to interrelate these definitions with other Salt definitions, and make all the database components work together.

How to do it...

We will use the same minion as the previous recipe.

  1. Create and edit /opt/salt-cookbook/staging/mysql/database.sls to have the following entries:

    include:
      - mysql
    
    MySQL-python:
      pkg.installed
    
    stg_databases:
      mysql_database.present:
        - name: stagingdb
        - require:
          - pkg: MySQL-python
          - service: mysql_service
    
    databases_to_remove:
      mysql_database.absent:
        - name: test
        - require:
          - pkg: MySQL-python
          - service: mysql_service
  2. Apply the state to the minion, using the following command:

    [root@salt-master ~]# salt 'salt-minion-mysql' state.sls mysql.database saltenv=staging
    salt-minion-mysql:
    ----------
              ID: mysql_package
        Function: pkg.installed
            Name: mysql-server
          Result: True
         Comment...