Install And Use SALTStack In A Mixed Environment - Page 4

On this page

  1. SALT STATE TREE

SALT STATE TREE

In case you followed this howto, you have a slight insight of how easy to simultaneously manage simple tasks on several servers.

Let's go one step towards. It is about manage complex tasks in complex environment by one command.

More details about it in -> http://docs.saltstack.com/ref/states/highstate.html

In order to have this feature, you have to configure your salt a little, at the folder /etc/salt

On your SALT MASTER, you should have a file, called: master

To get rid of commented lines, it looks like this:

[email protected]:/etc/salt# grep -E -v '^#|^ *$' /etc/salt/master

Edit it until the result should be:

state_top: top.sls
file_roots:
  base:
    - /srv/salt
log_file: /var/log/salt/master
key_logfile: /var/log/salt/key
log_level: debug

As a next step, we create three state files:

/srv/salt/top.sls       -> It is necessary
/srv/salt/motd.sls      -> It is optional
/srv/salt/line6svn.sls  -> It is optional

The top.sls file is the entry point, defined in /etc/salt/master

It gives the name of SaltStateFiles without ".sls"

State files contains commands and configuration directives.

You can also use fileter in servers name or other grains filter in everywhere is state tree.

cat /srv/salt/top.sls

base:
  '*':
    - motd
    - line6svn

It check out a Subversion repository:

[email protected]:/srv/salt# cat /srv/salt/line6svn.sls

https://svn.code.sf.net/p/line6linux/code/driver/trunk/:
  svn.latest:
    - target: /opt/Line6.SVN

You can manage text file:

[email protected]:/srv/salt# cat /srv/salt/motd.sls

motd_perms:
  file.managed:
    - name: /etc/motd
    - mode: 644
motd_quote:
  file.append:
    - name: /etc/motd
    - text: "Of all smells, bread; of all tastes, salt."

We can activate state tree by the following command:

[email protected]:/srv/salt# salt '*' state.highstate

salt-minion2.test.local:
----------
    State: - file
    Name:      /etc/motd
    Function:  managed
        Result:    True
        Comment:   File /etc/motd is in the correct state
        Changes:   
----------
    State: - file
    Name:      /etc/motd
    Function:  append
        Result:    True
        Comment:   Appended 0 lines
        Changes:   
----------
    State: - svn
    Name:      https://svn.code.sf.net/p/line6linux/code/driver/trunk/
    Function:  latest
        Result:    True
        Comment:   At revision 1072.
        Changes:   
Summary
------------
Succeeded: 3
Failed:    0
------------
Total:     3
salt-centos:
----------
    State: - file
    Name:      /etc/motd
    Function:  append
        Result:    True
        Comment:   Appended 0 lines
        Changes:   
----------
    State: - file
    Name:      /etc/motd
    Function:  managed
        Result:    True
        Comment:   File /etc/motd is in the correct state
        Changes:   
----------
    State: - svn
    Name:      https://svn.code.sf.net/p/line6linux/code/driver/trunk/
    Function:  latest
        Result:    True
        Comment:   At revision 1072.
        Changes:   
Summary
------------
Succeeded: 3
Failed:    0
------------
Total:     3

You can have a StateTree requst to the SaltMaster server from a Minion, like this:

[[email protected] ~]# salt-call state.highstate -l debug

Turninig off all minions:

[email protected]:~# salt '*' cmd.run "poweroff"

salt-centos:   
salt-minion2.test.local:    
salt-minion1.test.local:

Have a luck!

Share this page:

0 Comment(s)

Add comment

Comments

From: nagyorgy