7

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?

Kai Hatje
  • 431
  • 6
  • 17
  • 1
    I think your question is already asked here: https://stackoverflow.com/questions/44453092/whats-the-big-difference-between-execution-modules-and-state-modules/44455101#44455101 – Gijs Brandsma Jul 06 '17 at 09:29
  • 2
    Possible duplicate of [what's the big difference between execution modules and state modules](https://stackoverflow.com/questions/44453092/whats-the-big-difference-between-execution-modules-and-state-modules) – Mostafa Hussein Jul 06 '17 at 14:27
  • Thanks for the comments. It doesn't answer this exact question, but can help with a deeper understanding. @MostafaHussein fyi, your link is the same as gbrandsmas. – Kai Hatje Jul 06 '17 at 14:32
  • Yes they are the same as I have created a flag using @gbrandsma's comment, In general the mentioned answer is telling the difference between Salt Module and Salt State. Why do you think that the answer is not suitable for your question ? – Mostafa Hussein Jul 06 '17 at 14:36
  • Imho it answers on the difference between a state module and an execution module, from which one can deduce the answer to the question in this post. But it's not very clear. I for one didn't find it when searching, which is why I opened this question. – Kai Hatje Jul 06 '17 at 14:48
  • My explanation here might help: https://stackoverflow.com/questions/37253393/whats-the-differences-between-functions-in-state-file-and-functions-in-command/37259922#37259922 – Utah_Dave Jul 11 '17 at 22:56

1 Answers1

13

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

Black Phantom
  • 257
  • 2
  • 10