Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what's the big difference between execution modules and state modules

Recently, I'm learning salt from its doc. However, I'm quite confused about execution modules and state modules. Why there are two types of module? Why they can't unify? If we have just one type of module that can be used both on command line and in sls file, isn't it simpler and better?

like image 269
ldjhust Avatar asked Jun 09 '17 08:06

ldjhust


1 Answers

In short:

  • Execution modules: execute a task
  • States module: try to get to a certain state/configuration.

Execution modules:

They are designed to perform tasks on a minion. For example: mysql.query will query a specified database. The execution module does not check if the database needs to be queried or not. It just executes its task.
Have a look at the complete list of modules and you will see that they will just execute a task for you. https://docs.saltstack.com/en/latest/ref/modules/all/index.html

States module:

It's called THE states module.
The states module is a module too. But it's a special one. With the states module you can create states (the sls files under /srv/salt ) for your Minions.
You could for example create a state that ensures the Minion has a web server configured for www.example.com.

After you have created your state you can apply it with the states module: salt <minion> state.apply example_webserver

The example_webserver state specifies what the Minion needs to have. If the Minion is already in the correct state, it does nothing. If the Minion is not in the correct state it will try to get there.
The states module can be found here: https://docs.saltstack.com/en/latest/ref/states/all/salt.states.module.html

like image 162
Gijs Brandsma Avatar answered Sep 24 '22 04:09

Gijs Brandsma