Server management with salt – h6: LAMP with salt

This assignment was completed in full from my personal desktop, with a virtual machine running Ubuntu 18.04.1 x64

Apache and PHP (10.12 – 11:23)

I already have a salt module that installs, enables and configures Apache and LAMP. Here’s what it looks like:

apache2:
  pkg.installed

libapache2-mod-php:
  pkg.installed

/var/www/html/index.html:
  file.managed:
    - source: salt://apache_installer/index.html

/etc/apache2/mods-available/php7.2.conf:
  file.managed:
    - source: salt://apache_installer/php7.2.conf

/etc/apache2/mods-enabled/userdir.conf:
  file.symlink:
    - target: ../mods-available/userdir.conf

/etc/apache2/mods-enabled/userdir.load:
  file.symlink:
    - target: ../mods-available/userdir.load

/etc/apache2/mods-enabled/php7.2.conf:
  file.symlink:
    - target: ../mods-available/php7.2.conf

/etc/apache2/mods-enabled/php7.2.load:
  file.symlink:
    - target: ../mods-available/php7.2.load

apache2service:
  service.running:
    - name: apache2
    - watch:
      - file: /etc/apache2/mods-enabled/userdir.conf
      - file: /etc/apache2/mods-enabled/userdir.load

/home/xubuntu/public_html:
  file.recurse:
    - source: salt://apache_installer/public_html
    - include_empty: True

MariaDB installation via salt.

I created a new directory, init.sls, and pasted the code found here (in the comments):

mariadb-server:
  pkg.installed

mariadb-client:
  pkg.installed

/tmp/dbfile.sql:
  file.managed:
    - mode: 600
    - source: salt://mariadb/dbfile.sql

'cat /tmp/createuser.sql|mariadb -u root':
  cmd.run:
    - unless: "echo 'show databases'|sudo mariadb -u root|grep '^test123$'"

and here’s the dbfile.sql:

CREATE DATABASE test123;
GRANT ALL ON test123.* TO test123 IDENTIFIED BY 'EbOsTNXfna86HyZbJ27H3syqZREb3D';

what this state does::

  • installs MariaDB
  • copies the dbfile.sql into /tmp
  • Runs mariadb and pipes the contents of the file into it. (Thus creating test123 with given password)

Lähteet:

Leave a Reply

Your email address will not be published. Required fields are marked *