Wednesday, 24 February 2016

State system (High State & Low State) in SALT STACK:

For this example we are using top.sls and httpd_require.sls wihch contain,

# cat top.sls
base:
 '*':
  - httpd_require
root@ranjith1:/srv/salt# cat httpd_require.sls
install_httpd:
 pkg.installed:
   - name: httpd
 service.running:
  - name: httpd
  - enable: True
  - require:
    - file: install_httpd
 file.managed:
  - name: /var/www/html/index.html
  - source: salt://index1.html
  - user: root
  - group: root
  - mode: 644
  - require:
    - pkg: install_httpd

High state:

We can see all the aspects of high state system while working with state files( .sls), There are three specific components.

- High data:
- SLS file:
- High State

  - Each individual State represents a piece of high data.
   - for example:
       file.managed:
    - name: /var/www/html/index.html
    - source: salt://index1.html
    - user: root
    - group: root
    - mode: 644
    - require:
      - pkg: install_httpd
  - Salt will compile all relevant SLS inside the top.sls, When these files are tied together using includes, and further glued together for use inside an environment using a top.sls file, they form a High State.
we can see this using 'state.show_highstate',




First, an order is declared, All States that are set to be first will have their order adjusted accordingly. Salt will then add 10000 to the last defined number (which is 0 by default), and add any States that are not explicitly ordered.

Salt will also add some variables that it uses internally, to know which environment (__env__) to execute the State in, and which SLS file (__sls__) the State declaration came from, Remember that the order is still no more than a starting point; the actual High State will be executed based first on requisites, and then on order.

In other words, "High" data refers generally to data as it is seen by the user.

Low States:

"Low" data refers generally to data as it is ingested and used by Salt.

Once the final High State has been generated, it will be sent to the State compiler. This will reformat the State data into a format that Salt uses internally to evaluate
each declaration, and feed data into each State module (which will in turn call the execution modules, as necessary). As with high data, low data can be broken into individual components:
- Low State
- Low chunks
- State module
- Execution module(s)



Together, all this comprises a Low State. Each individual item is a Low Chunk. The first Low Chunk on this list looks like this:

- __env__: base
  __id__: install_httpd
  __sls__: httpd_require
  fun: installed
  name: http
  order: 10000
  state: pkg

Each low chunk maps to a State module (in this case, pkg) and a function inside that State module (in this case, installed). An ID is also provided at this level
(__id__). Salt will map relationships (that is, requisites) between States using a combination of State and __id__. If a name has not been declared by the user, then
Salt will automatically use the __id__ as the name.Once a function inside a State module has been called, it will usually map to one or more execution modules which actually do the work.

No comments:

Post a Comment