Topics


<aside> 💡 Execution modules are iterative, whereas state modules are declarative. Execution module functions perform a task. In general, when you call the same execution module multiple times in succession, it will run the same logic and commands under the hood each time.

</aside>

<aside> 💡 State module functions, on the other hand, are designed to be idempotent. An idempotent operation is one that only changes the result the first time it is applied. Subsequent applications do not continue to apply changes. Idempotent state modules functions are designed to do only as much work as necessary to create a given state on the target minion.

</aside>

Pieces of a state declaration

<ID Declaration>:    
 <State Module>.<Function>:      
  - name: <name>      
  - <Function Arg>      
  - <Function Arg>      
  - <Function Arg>      
  - <Requisite Declaration>:        
    - <Requisite Reference>
install_apache:    
     pkg.installed:      
	- name: apache2

Expanding to encompass multiple pieces of state

apache_installation:
  pkg.installed:
    - name: apache2

#The declaration ID can be anything u want
Make sure apache is running:
#We make use of service.running state module
  service.running:
    - name: apache2
    - enable: True

The require requisite

apache_installation:
  pkg.installed:
    - name: apache2

#The declaration ID can be anything u want
Make sure apache is running:
#We make use of service.running state module
  service.running:
    - name: apache2
    - enable: True
    #both the state module pkg and the state ID install_apache are required to define a require requisite
    - require: 
       - pkg.apache_installation

With this requisite in place, let's reorder the two state declarations in our apache.sls file

Make sure apache is running:
  service.running:
    - name: apache2
    - enable: True
    - require: 
       - pkg.apache_installation

apache_installation:
  pkg.installed:
    - name: apache2