Saltstack entry to the master tutorial (VII): Requisites

In configuration management, file a sls following there will be many modules to a coordinating role. In addition to the order of execution down from above, but also those of mutual dependency between the different modules it. In this section we take a look.

I am a small T-shaped people pay, an Internet practitioners adhere to lifelong learning. Like my blog I welcome the focus on csdn, if there is a problem please share in the comments section beneath, thank you.

requisites

The salt requisites designed to establish the dependencies between the different modules.requisites divided into two types, direct and requisites requisite_ins, except that the direction-dependent

In the following will be referred to requirethe type of dependency is an example

Represents a direct statement of the requisites module depends on the module is declared

vim:
  pkg.installed

/etc/vimrc:
  file.managed:
    - source: salt://edit/vimrc
    - require:
      - pkg: vim

There are two modules, respectively pkg, and file. Because filethe use of direct require, then filethis module will depend on the pkgmodule.

Requisite_ins direction on the contrary, they have been represented by other modules dependent

vim:
  pkg.installed:
    - require_in:
      - file: /etc/vimrc

/etc/vimrc:
  file.managed:
    - source: salt://edit/vimrc

Here it denotes pkgthat one module fileis a module which depend

Here dependencies declared format module:IDor module:name_value, that is to say in the example above, if this definition is also successfully defined dependencies

vimrc:
  file.managed:
    - name: /etc/vimrc
    - source: salt://edit/vimrc

require和watch

Dependent on the type of relationship of a total of two kinds, in addition to the above mentioned require, there is a watch. Of course, each respectively corresponding to the require_inand watch_informat.

require

require the most basic of dependency, it is relatively simple. It means to be dependent modules must perform than relying on the module, if the module is dependent on the successful implementation dependent modules If the failure is not performed.

Can also be directly dependent on the entire sls file, the entire file is executed successfully before the implementation of sls dependent module. The format, the first to include the dependent sls file, and then define dependency

include:
  - foo

bar:
  pkg.installed:
    - require:
      - sls: foo

require corresponding require_innot cite the example.

watch

In addition to watch all of the above functions require the outside, there are some additional features. watch keywords will be relied upon to detect whether a module which has mod_watchthis function, if not the function, then watch the results like require, if there is this function, then when the module is dependent on the target minion will trigger the generation of altered mod_watchfunction, which triggers the watch condition, such that dependent execution module.

In other words, if you go watch some functions will continue to produce a change of the target, for example file.managed, then each time a modification of the target system, will lead to the execution of the function configuration watch.

The best example is to restart the service

ntpd:
  service.running:
    - watch:
      - file: /etc/ntp.conf
  file.managed:
    - name: /etc/ntp.conf
    - source: salt://ntp/files/ntp.conf

Say a digression, I checked the official document, in fact, did not find mod_watch function salt.states.file this module inside, but the watch is still in effect, but also very strange

corresponding to watch watch_inon the child no additional example.

prereq

prereq this dependence is rather special, is dependent on the function will first to test=Trueperform smoke testing way, if the target system will produce change, then the implementation of functional dependencies.

Apply some updates must be stopped in case of services

graceful-down:
  cmd.run:
    - name: service apache graceful
    - prereq:
      - file: site-code

site-code:
  file.recurse:
    - name: /opt/site_code
    - source: salt://site/code

In this case when there is a change in the code file, apache service will first stopped, and then to update the code.

prereq corresponding prereq_into the child no additional example.

to sum up

Dependencies state file function enables execution of the function more flexible, so that the salt can adapt to more complex scenarios, it is an integral part of the production environment configuration items.

发布了25 篇原创文章 · 获赞 2 · 访问量 1639

Guess you like

Origin blog.csdn.net/Victor2code/article/details/104110740