Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SaltStack modules vs states

When searching for a functionality of SaltStack, often a state and a module turn up (when searching for "saltstack user" for example, one gets salt.states.user and salt.modules.user).

Reading the documentation, I get the impression that states somehow call modules or rather functions in modules, to achieve having the states set. But it's not very clear to me. Hence the following question:

What is the difference between a module and a state in SaltStack?

like image 365
Kai Hatje Avatar asked Jul 06 '17 08:07

Kai Hatje


1 Answers

First of all:

  • Modules are executed directly. If you execute some module repeatedly, it executes the task each time. E.g. if you execute salt.modules.file.copy repeatedly, it overwrites the already existing file each time you execute it.
  • States are something that describes how the desired state of a specific part of the targeted system should be afterwards. E.g. if you execute salt.states.file.copy repeatedly, it always checks if the file already exists and it only copies the file if it doesn`t already exist.

If you now look closer into the python source code of the states, you see, that the states use their associated modules most of the time. But they have some inspection before they execute them and they only execute them if the inspection says that the desired state doesn`t already exist.

I hope, this will make the difference a bit more clear

like image 107
Black Phantom Avatar answered Sep 23 '22 04:09

Black Phantom