Install And Use SALTStack In A Mixed Environment - Page 2

Testing the installed SaltStack

PING all running minions from Salt Master:

root@salt-master:~# salt '*' test.ping

You can use regexp in its name:

root@salt-master:~# salt 'salt-[m]*' test.ping

The result should be something like this:

salt-minion1.test.local:
    True
salt-minion2.test.local:
    True
root@salt-master:~# salt 'salt-[!m]*' test.ping

The result should be something like this:

salt-centos:
    True

 

Single usage of SaltStack

The following examples manage Salt-Minions from Salt-Master

 

Ask hostnames:

root@salt-master:~# salt '*' grains.item host
salt-minion1.test.local:
  host: salt-minion1
salt-minion2.test.local:
  host: salt-minion2
salt-centos:
  host: salt-centos

Ask Operating systems:

root@salt-master:~# salt '*' grains.item os
salt-minion2.test.local:
  os: Debian
salt-minion1.test.local:
  os: Debian
salt-centos:
  os: CentOS

Find files by name:

root@salt-master:~# salt '*' file.find /etc name=host\*.\*
salt-centos:
    - /etc/host.conf
    - /etc/hosts.allow
    - /etc/hosts.deny
salt-minion2.test.local:
    - /etc/host.conf
    - /etc/hosts.allow
    - /etc/hosts.deny
    - /etc/init.d/hostname.sh
salt-minion1.test.local:
    - /etc/host.conf
    - /etc/hosts.allow
    - /etc/hosts.deny
    - /etc/init.d/hostname.sh

Find content of text file:

root@salt-master:~# salt '*' file.contains /etc/ssh/sshd_config 'Port'
salt-centos:
    True
salt-minion1.test.local:
    True
salt-minion2.test.local:
    True

Edit content of text file:

root@salt-master:~# salt '*' file.sed /etc/ssh/sshd_config 'Port 22' 'Port 2201'
salt-minion2.test.local:
    ----------
    pid:
        2555
    retcode:
        0
    stderr:
        
    stdout:
        
salt-minion1.test.local:
    ----------
    pid:
        2476
    retcode:
        0
    stderr:
        
    stdout:
        
salt-centos:
    ----------
    pid:
        1490
    retcode:
        0
    stderr:
        
    stdout:

Create folder:

root@salt-master:~# salt '*' file.makedirs /tmp/testFolder/
salt-minion2.test.local:
    None
salt-minion1.test.local:
    None
salt-centos:
    None

Create empty file:

root@salt-master:~# salt '*' file.touch /tmp/testFolder/emptyFile
salt-centos:
    True
salt-minion1.test.local:
    True
salt-minion2.test.local:
    True

Remove directory tree:

root@salt-master:~# salt '*' file.remove /tmp/testFolder/
salt-minion1.test.local:
    True
salt-minion2.test.local:
    True
salt-centos:
    True

Manage /etc/hosts file:

root@salt-master:~# salt '*' hosts.add_host 192.168.122.1 kvmhost.test.local
salt-minion2.test.local:
    True
salt-centos:
    True
salt-minion1.test.local:
    True

Manage services on Minions from Master:

salt '*' service.get_all
salt '*' service.status nginx
salt '*' service.reload ssh
salt '*' service.disable rsync
salt '*' service.get_disabled

You will receive Fails if service is not installed.

 

Package installation to Minions from Master:

We can install packages by one single command on various distributions at the same time by:

root@salt-master:/srv/salt# salt '*' pkg.install subversion
salt-centos:
    ----------
    apr:
        ----------
        new:
            1.3.9-5.el6_2
        old:
    apr-util:
        ----------
        new:
            1.3.9-3.el6_0.1
        old:
    gnutls:
        ----------
        new:
            2.8.5-10.el6_4.2
        old:
    libproxy:
        ----------
        new:
            0.3.0-4.el6_3
        old:
    libproxy-bin:
        ----------
        new:
            0.3.0-4.el6_3
        old:
    libproxy-python:
        ----------
        new:
            0.3.0-4.el6_3
        old:
    libtasn1:
        ----------
        new:
            2.3-3.el6_2.1
        old:
    neon:
        ----------
        new:
            0.29.3-3.el6_4
        old:
    pakchois:
        ----------
        new:
            0.4-3.2.el6
        old:
    perl-URI:
        ----------
        new:
            1.40-2.el6
        old:
    subversion:
        ----------
        new:
            1.6.11-9.el6_4
        old:
salt-minion1.test.local:
    ----------
    libapr1:
        ----------
        new:
            1.4.6-3+deb7u1
        old:
    libaprutil1:
        ----------
        new:
            1.4.1-3
        old:
    libneon27-gnutls:
        ----------
        new:
            0.29.6-3
        old:
    libsvn1:
        ----------
        new:
            1.6.17dfsg-4+deb7u4
        old:
    subversion:
        ----------
        new:
            1.6.17dfsg-4+deb7u4
        old:

After the installation, we can check the result:

root@salt-master:/srv/salt# salt '*' cmd.run "svn --version --quiet"
salt-minion2.test.local:
    1.6.17
salt-minion1.test.local:
    1.6.17
salt-centos:
    1.6.11

 

Install MYSQL on Debian minions

It is a bit complicated than a single package

root@salt-master:~# salt 'salt-mini*' pkg.install python-mysqldb
salt-minion1.test.local:
    ----------
    libmysqlclient18:
        ----------
        new:
            5.5.31+dfsg-0+wheezy1
        old:
            
    mysql-common:
        ----------
        new:
            5.5.31+dfsg-0+wheezy1
        old:
            
    python-mysqldb:
        ----------
        new:
            1.2.3-2
        old:
            
            
salt-minion2.test.local:
    ----------
    libmysqlclient18:
        ----------
        new:
            5.5.31+dfsg-0+wheezy1
        old:
            
    mysql-common:
        ----------
        new:
            5.5.31+dfsg-0+wheezy1
        old:
    python-mysqldb: 
        ----------
        new:
            1.2.3-2
        old:

If you try out this command on all of your servers, you can see, something went wrong with CentOS.

You can see details in /var/log/salt/minion. If it not tell you enough, raise loglevel in /etc/salt/minion.

I will not go into the details, but not difficult to solve this.

If you want to manage mysql by SaltStack, you should have a file mysql_salt.conf.

As it was mentioned previously, you can manage this remotely too:

root@salt-master:~# salt 'salt-mini*' file.append /etc/salt/minion.d/mysql_salt.conf \ "mysql.host: 'localhost'" \ "mysql.port: 3306" \ "mysql.user: 'root'" \ "mysql.pass: ''" \ "mysql.db: 'mysql'"
salt-minion2.test.local:
    Wrote 5 lines to "/etc/salt/minion.d/mysql_salt.conf"
salt-minion1.test.local:
    Wrote 5 lines to "/etc/salt/minion.d/mysql_salt.conf"

At this point Salt-Minion restart needed.

The salt can not restart itself as "salt 'salt-mini*' service.restart salt-minion", so you have to use a trick:

root@salt-master:~# salt 'salt-mini*' cmd.run "/etc/init.d/salt-minion restart"
salt-minion2.test.local:
    Restarting salt minion control daemon: salt-minion.
salt-minion1.test.local:
    Restarting salt minion control daemon: salt-minion.
root@salt-master:~# salt 'salt-mini*' pkg.install mysql-server
salt-minion1.test.local:
    ----------
    libaio1:
        ----------
        new:
            0.3.109-3
        old:
    libdbd-mysql-perl:
        ----------
        new:
            4.021-1+b1
        old:
    libdbi-perl:
        ----------
        new:
            1.622-1
        old:
    libhtml-template-perl:
        ----------
        new:
            2.91-1
        old:
    libnet-daemon-perl:
        ----------
        new:
            0.48-1
        old:
    libplrpc-perl:
        ----------
        new:
            0.2020-2
        old:
    mysql-client-5.5:
        ----------
        new:
            5.5.31+dfsg-0+wheezy1
        old:
    mysql-server:
        ----------
        new:
            5.5.31+dfsg-0+wheezy1
        old:
    mysql-server-5.5:
        ----------
        new:
            5.5.31+dfsg-0+wheezy1
        old:
    mysql-server-core-5.5:
        ----------
        new:
            5.5.31+dfsg-0+wheezy1
        old:
salt-minion2.test.local:
    ----------
    libaio1:
        ----------
        new:
            0.3.109-3
        old:
    libdbd-mysql-perl:
        ----------
        new:
            4.021-1+b1
        old:
    libdbi-perl:
        ----------
        new:
            1.622-1
        old:
    libhtml-template-perl:
        ----------
        new:
            2.91-1
        old:
    libnet-daemon-perl:
        ----------
        new:
            0.48-1
        old:
    libplrpc-perl:
        ----------
        new:
            0.2020-2
        old:
    mysql-client-5.5:
        ----------
        new:
            5.5.31+dfsg-0+wheezy1
        old:
    mysql-server:
        ----------
        new:
            5.5.31+dfsg-0+wheezy1
        old:
    mysql-server-5.5:
        ----------
        new:
            5.5.31+dfsg-0+wheezy1
        old:
    mysql-server-core-5.5:
        ----------
        new:
            5.5.31+dfsg-0+wheezy1
        old:

 

MySQL management on Minions from Salt-master

By now, you can use SaltStack DB managment commands on your Debian machines:

root@salt-master:~# salt 'salt-mini*' mysql.db_create 'dbname'
salt-minion2.test.local:
    True
salt-minion1.test.local:
    True
root@salt-master:~# salt 'salt-mini*' mysql.db_list
salt-minion2.test.local:
    - information_schema
    - dbname
    - mysql
    - performance_schema
    - test
salt-minion1.test.local:
    - information_schema
    - dbname
    - mysql
    - performance_schema
    - test
Share this page:

0 Comment(s)