Skip to content

Instantly share code, notes, and snippets.

@hbokh
Last active July 13, 2019 11:39
Show Gist options
  • Save hbokh/599b95815999e0e80ac21b4e07d8e5ef to your computer and use it in GitHub Desktop.
Save hbokh/599b95815999e0e80ac21b4e07d8e5ef to your computer and use it in GitHub Desktop.
Install SaltShaker on Ubuntu 16.04.1 LTS

This is a "best-effort" in translating the "install.txt" from SaltShaker into English.
I tried all steps myself on a recent Ubuntu-host and latest SaltStack-packages.


This installation note applies to SaltShaker v2.1.3.

SaltShaker on Ubuntu 16.04.1 LTS

NOTE All commands are to be run as user "root".

Install and upgrade pip

apt-get install python-pip
pip install --upgrade pip

This will install pip v8.1.1 and upgrade it to v9.0.1.

Install SaltStack

Official documentation: https://repo.saltstack.com/#ubuntu

Run the following command to import the SaltStack repository key:

apt-key adv --fetch-keys http://repo.saltstack.com/apt/ubuntu/16.04/amd64/latest/SALTSTACK-GPG-KEY.pub

Save the following file to /etc/apt/sources.list.d/saltstack.list:

deb http://repo.saltstack.com/apt/ubuntu/16.04/amd64/latest xenial main

Update packages and install SaltStack

apt-get update
apt-get install salt-master
apt-get install salt-minion
apt-get install salt-syndic
apt-get install salt-api

Clone the SaltShaker-repo

Run git clone [email protected]:yueyongyue/saltshaker.git
Enter the directory: cd saltshaker.

Salt-API configuration

Using system pam for authentication, add a user "admin":

useradd -M -s /sbin/nologin admin
passwd admin

User Name: admin
Password: admin

Add the saltapi.conf file (or just copy the one included in the repo):

vi /etc/salt/master.d/saltapi.conf

rest_cherrypy:
  port: 8000
  host: 0.0.0.0
  disable_ssl: true
external_auth:
  pam:
    admin:
        - .*
        - '@runner'
        - '@wheel'

Restart the Salt-master and -API:

/etc/init.d/salt-master restart
/etc/init.d/salt-api restart

Check with netstat -tlpn | grep 8000 if port 8000 is up and listening.

Python installation and configuration

Create a file requirements.txt and add:

cherrypy==3.8.0
django==1.8.4
django-crontab
mysql-python
django-celery==3.1.17
celery==3.1.17

Run pip install -r requirements.txt and you're done. No need to do pip-related installs by hand.

Setup of SaltShaker

Make a destination for the log-files:

mkdir -p /var/log/saltshaker/

Configure the database and Salt-API authentication information.

The file settings.py can be found in the (sub-)directory saltshaker/saltshaker.
Most of the settings have already been defined.

vi settings.py

DATABASES = {
  'Default': {
    'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', sqlite3' or 'oracle'.
    'NAME': 'saltshaker', # Or path to database file if using sqlite3.
    'USER': 'root', # Not used with sqlite3.
    'PASSWORD': 'sina', # Not used with sqlite3.
    'HOST': 'localhost', # Set to empty string for localhost. Not used with sqlite3.
    'PORT': '3306', # Set to empty string for default. Not used with sqlite3.
  }
}

According to the added system user information, add the following information to settings.py to configure the Salt-API authentication:

# SaltStack API
SALT_API_URL = 'http://127.0.0.1:8000'
SALT_API_USER = 'admin'
SALT_API_PASSWD = 'admin'

Install RabbitMQ

For more details, see http://www.rabbitmq.com/install-debian.html

apt-get install rabbitmq-server

Enable the rabbitmq-management plugin:

rabbitmq-plugins enable rabbitmq_management

Restart RabbitMQ:

rabbitmqctl stop
/etc/init.d/rabbitmq-server start

For security-reasons, you can access the management-interface on localhost only: 127.0.0.1:15672

Username: guest
Password: guest

Configure Celery and RabbitMQ

vi settings.py

platforms.C_FORCE_ROOT = True # Running a worker with superuser privileges
djcelery.setup_loader()
BROKER_HOST = "127.0.0.1"
BROKER_PORT = 5672
BROKER_USER = "guest"
BROOKER_PASSWORD = "guest"
BROKER_VHOST = "/"

Start Celery worker

python manage.py celery worker --loglevel=info -c 5

MySQL database setup

MySQL-database preparation:

create database saltshaker;
use saltshaker;
source /root/saltshaker/saltshaker-init.sql.txt

This will import the database-tables and -defaults.

Add a scheduled task / cronjob

python manage.py crontab add

Adds a scheduled task to get the number of queues.

Start the web-service

python manage.py runserver 0.0.0.0:80

Use your browser to open http://127.0.0.1

Initial user name: admin
Initial password: admin

SaltShaker on CentOS6.X

Install SaltStack

rpm --import https://repo.SaltStack.com/yum/redhat/6/x86_64/latest/SaltStack-GPG-KEY.pub
yum clean all
yum install salt-master salt-minion salt-api salt-syndic

For RabbitMQ on CentOS: http://www.rabbitmq.com/install-rpm.html

Other software installation and configuration

Runs saltshaker using nginx and uwsgi

pip install uwsgi django-uwsgi

See https://uwsgi-docs.readthedocs.org/en/latest/tutorials/Django_and_nginx.html

yum install nginx


It was said to ignore the following contents

Return data to MySQL

vi /etc/salt/master

Add the following line at the end of the line using MasterJobCache-Master-SideReturner This storage model

mysql.host: '127.0.0.1'
mysql.user: 'root'
mysql.pass: 'sina'
mysql.db: 'saltshaker'
mysql.port: 3306

#### Returner job cache to MySQL

Master_job_cache: mysql  

service salt-master restart

Modify the salt mysql.py file /usr/lib/python2.7/dist-packages/salt/returners/mysql.py The default database field is fun jid return id success full_ret alter_time
Since return is a keyword in python, you can not create this field in django's models so modify the field to fun jid returns minion_id success full_ret alter_time.
That is, modify the mysql.py line 235, as follows

The official build statement: https://docs.saltstack.com/en/latest/ref/returners/all/salt.returners.mysql.html

228 def returner (ret):
229 '' '
230 Return data to a mysql server
231 '' '
232 try:
233 with _get_serv (ret, commit = True) as cur:
234 sql = '' 'INSERT INTO `salt_returns`
235 (`fun`,` jid`, `returns`,` minion_id`, `success`,` full_ret`)
236 VALUES (% s,% s,% s,% s,% s,% s) '' '
237
238 cur.execute (sql, (ret ['fun'], ret ['jid'],
239 json.dumps (ret ['return']),
240 ret ['id'],
241 ret.get ('success', False),
242 json.dumps (ret)))
243 except salt.exceptions.SaltMasterError as exc:
244 log.critical (exc)
245 log.critical ('Could not store return with MySQL returner. MySQL server unavailable.')

@sequeiradenzil
Copy link

Thanks

@LawrenceIRL
Copy link

LawrenceIRL commented Apr 11, 2018

@hbokh Is there any chance of another best effort translation of https://github.com/yueyongyue/saltshaker_api + https://github.com/yueyongyue/saltshaker_frontend readme/install docs as it looks like SaltShaker Plus is what's linked to now in the SaltShaker repo (which links to the two linked above). Unfortunately for translation reasons, it looks to be one of the better GUI options for Salt Open that is out there and I'm guessing it's being updated now for compatibility although I'm not sure how far along it is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment