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?
问题:
回答1:
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