设为首页 收藏本站
查看: 1386|回复: 0

[经验分享] saltstack官方文档——Highstate data structure definitions

[复制链接]

尚未签到

发表于 2015-11-26 11:11:05 | 显示全部楼层 |阅读模式
  转自:http://docs.saltstack.com/ref/states/highstate.html#term-state-tree
  

Highstate data structure definitions

THE SALT STATE TREE

Top file
The main state file that instructs minions what environment and modules to use during state execution.
  Configurable via state_top.

See also
A detailed description of the top file


State treeA collection of SLS files that live under the directory specified in file_roots.
A state tree can be organized into SLS modules.
Include declaration


Include declaration
Defines a list of module reference strings to include in this SLS.
Occurs only in the top level of the highstate structure.

  Example:

include:
- edit.vim
- http.server


Module reference

Module referenceThe name of a SLS module defined by a separate SLS file and residing on the Salt Master. A module namededit.vim is a reference to the SLS file salt://edit/vim.sls.
ID declaration

ID declaration
Defines an individual highstate component. Always references a value of a dictionary containing keys referencing state
declarations and requisite declarations. Can be overridden by a name
declaration or anames declaration.
  Occurs on the top level or under the extend declaration.
Must be unique across entire state tree. If the same ID declaration is used twice, only the first one matched will be used. All subsequent ID declarations with the same name will be ignored.


Note
  Naming gotchas
Until 0.9.6, IDs could not contain a dot, otherwise highstate summary output was unpredictable. (It was fixed in versions 0.9.7 and above)

Extend declaration


Extend declaration
Extends a name declaration from an included SLS module.
The keys of the extend declaration always define existing ID declarations which have been
defined in included SLS modules.
Occurs only in the top level and defines a dictionary.

  Extend declarations are useful for adding-to or overriding parts of a state declaration that
is defined in anotherSLS file. In the following contrived example, the shown mywebsite.sls file is include -ing
and extend -ing theapache.sls module in order to add a watch declaration
that will restart Apache whenever the Apache configuration file, mywebsite changes.

include:
- apache
extend:
apache:
service:
- watch:
- file: mywebsite
mywebsite:
file:
- managed
.. seealso:: watch_in and require_in
Sometimes it is more convenient to use the :term:`watch_in` or
:term:`require_in` syntax instead of extending another ``SLS``
file.
:doc:`State Requisites </ref/states/requisites>`


State declaration

State declaration
A list which contains one string defining the function declaration and
any number of function arg declarationdictionaries.
  Can, optionally, contain a number of additional components like the name override components — name andnames.
Can also contain requisite declarations.
Occurs under an ID declaration.


Requisite declaration


Requisite declaration
A list containing requisite references.
  Used to build the action dependency tree. While Salt states are made to execute in a deterministic order, this order is managed by requiring and watching other Salt states.
Occurs as a list component under a state declaration or as
a key under an ID declaration.


Requisite reference


Requisite reference
A single key dictionary. The key is the name of the referenced state
declaration and the value is the ID of the referenced ID declaration.
Occurs as a single index in a requisite declaration list.


Function declaration


Function declaration
The name of the function to call within the state. A state declaration can contain only a single function declaration.
  For example, the following state declaration calls the installed function
in the pkg state module:

httpd:
pkg.installed

  The function can be declared inline with the state as a shortcut, but the actual data structure is better referenced in this form:

httpd:
pkg:
- installed

  Where the function is a string in the body of the state declaration. Technically when the function is declared in dot notation the compiler converts it to be a string in the state declaration list. Note that the use of the first example more than
once in an ID declaration is invalid yaml.
  INVALID:

httpd:
pkg.installed
service.running

  When passing a function without arguments and another state declaration within a single ID declaration, then the long or &quot;standard&quot; format needs to be used since otherwise it does not represent a valid data structure.
  VALID:

httpd:
pkg:
- installed
service:
- running

Occurs as the only index in the state declaration list.


Function arg declaration


Function arg declaration
A single key dictionary referencing a Python type which is to be passed to the named function
declaration as a parameter. The type must be the data type expected by the function.
Occurs under a function declaration.

  For example in the following state declaration user, group, and mode are
passed as arguments to the managedfunction
in the file state module:

/etc/http/conf/http.conf:
file.managed:
- user: root
- group: root
- mode: 644


Name declaration

Name declaration
Overrides the name argument of a state
declaration. If name is not specified the ID
declaration satisfies thename argument.
The name is always a single key dictionary referencing a string.

  Overriding name is useful for a variety of scenarios.
  For example, avoiding clashing ID declarations. The following two state declarations cannot both have/etc/motd as the ID declaration:

motd_perms:
file.managed:
- name: /etc/motd
- mode: 644
motd_quote:
file.append:
- name: /etc/motd
- text: &quot;Of all smells, bread; of all tastes, salt.&quot;

  Another common reason to override name is if the ID declaration is long and needs to be referenced in multiple places. In the example below it is much easier to specify mywebsite than
to specify /etc/apache2/sites-available/mywebsite.com multiple times:

mywebsite:
file.managed:
- name: /etc/apache2/sites-available/mywebsite.com
- source: salt://mywebsite.com
a2ensite mywebsite.com:
cmd.wait:
- unless: test -L /etc/apache2/sites-enabled/mywebsite.com
- watch:
- file: mywebsite
apache2:
service:
- running
- watch:
- file: mywebsite


Names declaration

Names declarationExpands the contents of the containing state declaration into multiple
state declarations, each with its own name.  For example, given the following state declaration:

python-pkgs:
pkg.installed:
- names:
- python-django
- python-crypto
- python-yaml

  Once converted into the lowstate data structure the above state declaration will be expanded into the following three state declarations:

python-django:
pkg.installed
python-crypto:
pkg.installed
python-yaml:
pkg.installed


LARGE EXAMPLE
  Here is the layout in yaml using the names of the highdata structure components.

<Include Declaration>:
- <Module Reference>
- <Module Reference>
<Extend Declaration>:
<ID Declaration>:
[<overrides>]

# standard declaration
<ID Declaration>:
<State Declaration>:
- <Function>
- <Function Arg>
- <Function Arg>
- <Function Arg>
- <Name>: <name>
- <Requisite Declaration>:
- <Requisite Reference>
- <Requisite Reference>

# inline function and names
<ID Declaration>:
<State Declaration>.<Function>:
- <Function Arg>
- <Function Arg>
- <Function Arg>
- <Names>:
- <name>
- <name>
- <name>
- <Requisite Declaration>:
- <Requisite Reference>
- <Requisite Reference>

# multiple states for single id
<ID Declaration>:
<State Declaration>:
- <Function>
- <Function Arg>
- <Name>: <name>
- <Requisite Declaration>:
- <Requisite Reference>
<State Declaration>:
- <Function>
- <Function Arg>
- <Names>:
- <name>
- <name>
- <Requisite Declaration>:
- <Requisite Reference>


  

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-143827-1-1.html 上篇帖子: Salt Stack初探之另外一种用Python写的配置管理系统(saltstack实例) 下篇帖子: 使用saltstack部署openstack
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表