STATES TUTORIAL, PART 4

本教程建立在第1部分第2部分第3部分涵盖的主题上。建议您从此开始。这章教程我们将讨论更多 sls 文件的扩展模板和配置技巧。

This part of the tutorial will show how to use salt's file_roots to set up a workflow in which states can be "promoted" from dev, to QA, to production.

本教程的这一部分将展示如何使用salt的file_roots来设置一个工作流程,在这个工作流程中,状态可以从开发,QA到生产“推广”。

salt fileserver path inheritance

Salt's fileserver allows for more than one root directory per environment, like in the below example, which uses both a local directory and a secondary location shared to the salt master via NFS:

salt的文件服务器允许每个环境有多个根目录,就像下面的例子一样,它使用本地目录和通过nfs共享给salt master的辅助位置:

# In the master config file (/etc/salt/master)
file_roots:
base:
- /srv/salt
- /mnt/salt-nfs/base

Salt's fileserver collapses the list of root directories into a single virtual environment containing all files from each root. If the same file exists at the same relative path in more than one root, then the top-most match "wins". For example, if /srv/salt/foo.txt and /mnt/salt-nfs/base/foo.txt both exist, then salt://foo.txt will point to /srv/salt/foo.txt.

Salt的文件服务器将根目录列表压缩到包含每个根目录中的所有文件的单个虚拟环境中。 如果同一文件存在于多个根中的相同路径中,则最顶部的匹配项为“wins”。 例如,如果/srv/salt/foo.txt和/mnt/salt-nfs/base/foo.txt都存在,则salt://foo.txt将指向/srv/salt/foo.txt。

注意
When using multiple fileserver backends, the order in which they are listed in the fileserver_backend parameter also matters. If both roots and git backends contain a file with the same relative path, and roots appears before git in the fileserver_backend list, then the file in roots will "win", and the file in gitfs will be ignored.
当使用多个文件服务器后端时,它们在fileserver_backend参数中列出的顺序也很重要。 如果根目录和git后端都包含具有相同相对路径的文件,并且根目录位于fileserver_backend列表中的git之前,则根目录中的文件将“win”,并且gitfs中的文件将被忽略。
A more thorough explanation of how Salt's modular fileserver works can be found here. We recommend reading this.
关于Salt的模块化文件服务器如何工作的更全面的解释可以在这里(File Server Backends)找到。 我们推荐阅读。

environment configuration

Configure a multiple-environment setup like so:

像这样配置一个多环境设置:

file_roots:
base:
- /srv/salt/prod
qa:
- /srv/salt/qa
- /srv/salt/prod
dev:
- /srv/salt/dev
- /srv/salt/qa
- /srv/salt/prod

Given the path inheritance described above, files within /srv/salt/prod would be available in all environments. Files within /srv/salt/qa would be available in both qa, and dev. Finally, the files within /srv/salt/dev would only be available within the dev environment.

给定上面描述的路径继承,/srv/salt/prod中的文件将在所有环境中可用。 /srv/salt/qa中的文件在qa和dev中均可用。 最后,/srv/salt/dev中的文件只能在dev环境中使用。

Based on the order in which the roots are defined, new files/states can be placed within /srv/salt/dev, and pushed out to the dev hosts for testing.

根据定义根的顺序,可以将新文件/状态放置在/ srv / salt / dev中,并推送到开发主机进行测试。

Those files/states can then be moved to the same relative path within /srv/salt/qa, and they are now available only in the dev and qa environments, allowing them to be pushed to QA hosts and tested.

那些文件/状态可以被移动到/ srv / salt / qa中相同的相对路径,现在它们只能在dev和qa环境中使用,从而可以将它们推送到qa主机并进行测试。

Finally, if moved to the same relative path within /srv/salt/prod, the files are now available in all three environments.

最后,如果移动/srv/salt/prod中相同的相对路径,则这三个文件现在都可用于所有三种环境。

requesting files from specific fileserver environments

(从特定文件服务器环境请求文件)

See here for documentation on how to request files from specific environments.

有关如何从特定环境请求文件的文档,请参阅此处。

PRACTICAL EXAMPLE

As an example, consider a simple website, installed to /var/www/foobarcom. Below is a top.sls that can be used to deploy the website:

作为一个例子,考虑一个简单的网站,安装到/var/www/foobarcom. 以下是可用于部署网站的top.sls:

/srv/salt/prod/top.sls:

[root@SaltMaster1(10.182.88.136)]$~:>more /srv/salt/prod/top.sls
base:
'web*prod*':
- webserver.foobarcom
qa:
'web*qa*':
- webserver.foobarcom
dev:
'web*dev*':
- webserver.foobarcom

Using pillar, roles can be assigned to the hosts:

使用pillar,可以将角色分配给主机:

/srv/pillar/top.sls:

 [root@SaltMaster1(10.182.88.136)]$~:>mkdir -pv /srv/pillar
[root@SaltMaster1(10.182.88.136)]$~:>more /srv/pillar/top.sls
se:
'web*prod*':
- webserver.prod
'web*qa*':
- webserver.qa
'web*dev*':
- webserver.dev

/srv/pillar/webserver/prod.sls:

 [root@SaltMaster1(10.182.88.136)]$~:>mkdir -pv /srv/pillar/webserver
[root@SaltMaster1(10.182.88.136)]$~:>more /srv/pillar/webserver/prod.sls
erver_role: prod

/srv/pillar/webserver/qa.sls:

[root@SaltMaster1(10.182.88.136)]$~:>more  /srv/pillar/webserver/qa.sls 
webserver_role: qa

/srv/pillar/webserver/dev.sls:

[root@SaltMaster1(10.182.88.136)]$~:>more /srv/pillar/webserver/dev.sls
erver_role: dev

And finally, the SLS to deploy the website:

最后,通过SLS文件来部署网站:

/srv/salt/prod/webserver/foobarcom.sls:

{% if pillar.get('webserver_role', '') %}
/var/www/foobarcom:
file.recurse:
- source: salt://webserver/src/foobarcom
- env: {{ pillar['webserver_role'] }}
- user: www
- group: www
- dir_mode: 755
- file_mode: 644
{% endif %}

Given the above SLS, the source for the website should initially be placed in /srv/salt/dev/webserver/src/foobarcom.

鉴于上述SLS,网站的源码应放置在/srv/salt/dev/webserver/src/foobarcom中。

First, let's deploy to dev. Given the configuration in the top file, this can be done using state.apply:

首先,让我们部署到dev环境。 鉴于top文件中的配置,这可以使用state.apply完成:

salt --pillar 'webserver_role:dev' state.apply

However, in the event that it is not desirable to apply all states configured in the top file (which could be likely in more complex setups), it is possible to apply just the states for the foobarcom website, by invoking state.apply with the desired SLS target as an argument:

但是,如果不希望应用top文件中配置的所有状态(这可能在更复杂的设置中可能),则可以仅通过调用state.apply来应用foobarcom网站的状态希望的SLS目标作为参数:

salt --pillar 'webserver_role:dev' state.apply webserver.foobarcom

Finally, once the site has been tested in qa, then the files can be moved from /srv/salt/qa/webserver/src/foobarcom to /srv/salt/prod/webserver/src/foobarcom, and deployed using the following:

最后,一旦该网站已经在qa中进行了测试,则可以将文件从/srv/salt/qa/webserver/src/foobarcom移动到/srv/salt/prod/webserver/src/foobarcom, 并使用以下方法进行部署:

salt --pillar 'webserver_role:prod' state.apply webserver.foobarcom

Thanks to Salt's fileserver inheritance, even though the files have been moved to within /srv/salt/prod, they are still available from the same salt:// URI in both the qa and dev environments.

感谢Salt的fileserver继承性,即使文件已经移动到/srv/salt/prod中,它们仍然可以从qa和dev环境中的相同salt:// URI获得。

继续学习途径:

The best way to continue learning about Salt States is to read through the reference documentation and to look through examples of existing state trees. Many pre-configured state trees can be found on GitHub in the saltstack-formulas collection of repositories.

继续学习有关Salt Staes的最好方法是阅读参考文献并查看现有状态树的例子。许多预先配置的状态树可以在GitHub的saltstack-formula集合中找到。

If you have any questions, suggestions, or just want to chat with other people who are using Salt, we have a very active community and we'd love to hear from you.

如果您有任何问题,建议,或者只是想与其他使用Salt的人聊天,我们有一个非常活跃的社区,我们很乐意听取您的意见。

In addition, by continuing to the Orchestrate Runner docs, you can learn about the powerful orchestration of which Salt is capable.

另外,通过继续使用Orchestrate Runner文档,您可以了解Salt所具备的强大的协调功能。

【SaltStack官方版】—— states教程, part 4 - states 说明的更多相关文章

  1. 【SaltStack官方版】—— states教程, part 2 - 更复杂的states和必要的事物

    states tutorial, part 2 - more complex states, requisites 本教程建立在第1部分涵盖的主题上.建议您从此处开始. 在Salt States教程的 ...

  2. 【SaltStack官方版】—— states教程, part 3 - 定义,包括,延伸

    STATES TUTORIAL, PART 3 - TEMPLATING, INCLUDES, EXTENDS 本教程建立在第1部分和第2部分涵盖的主题上.建议您从此开始.这章教程我们将讨论更多  s ...

  3. 【SaltStack官方版】—— job management

    JOB MANAGEMENT New in version 0.9.7. Since Salt executes jobs running on many systems, Salt needs to ...

  4. 【SaltStack官方版】—— returners——返回器

    ETURNERS 返回器 By default the return values of the commands sent to the Salt minions are returned to t ...

  5. 【SaltStack官方版】—— STORING JOB RESULTS IN AN EXTERNAL SYSTEM

    STORING JOB RESULTS IN AN EXTERNAL SYSTEM After a job executes, job results are returned to the Salt ...

  6. 【SaltStack官方版】—— MANAGING THE JOB CACHE

    MANAGING THE JOB CACHE The Salt Master maintains a job cache of all job executions which can be quer ...

  7. 【SaltStack官方版】—— Events&Reactor系统—BEACONS

    Events&Reactor系统—BEACONS Beacons let you use the Salt event system to monitor non-Salt processes ...

  8. 【SaltStack官方版】—— Events&Reactor系统—EVENT SYSTEM

    Events&Reactor系统 EVENT SYSTEM The Salt Event System is used to fire off events enabling third pa ...

  9. 【SaltStack官方版】—— EVENTS & REACTOR指南

    EVENTS & REACTOR Event System Event Bus Event types Salt Master Events Authentication events Sta ...

随机推荐

  1. spring hibernate 事务整合 使用测试类 事务不自动提交的问题!!!

    使用JUnit 测试hibernate 事务管理的时候应注意 ,测试类完成是默认回滚的. 所以只能查询数据库却不能增删改数据库. 应该在测试类上面加上注解 @Rollback(false)  表似默认 ...

  2. oracle dis系列课程总结

    oracle dis系列课程总结 1 bbed安装和介绍 --1 bbed的安装--(Oracle Block Brower and EDitor Tool) 2 controlfile 丢失的恢复 ...

  3. 【Spring】---【IOC入门案例】

    第一步:导入Jar包 第二步:创建类,在类里面创建方法 public class User { public void add(){ System.out.println("-------- ...

  4. 【HANA系列】SAP HANA数据处理的理解与分析一

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[HANA系列]SAP HANA数据处理的理解与 ...

  5. 深入理解java:1. JVM虚拟机的构成

    1.JVM虚拟机的构成 什么是Java虚拟机? 作为一个Java程序员,我们每天都在写Java代码,我们写的代码都是在一个叫做Java虚拟机的东西上执行的. 但是如果要问什么是虚拟机,恐怕很多人就会模 ...

  6. Oracle 查看一个数据库实例下面所有的表大小

    1. 因为 oracle有一些 lob字段 在user_extents 里面取出来的结果不是表名, 所以需要与user_lobs 表做关联查询才可以 本来想通过 关联查询来实现, 发现字表查询更简单 ...

  7. Java数据结构之递归(Recursion)

    1. 递归解决问题 各种数学问题如:8皇后问题,汉诺塔,阶乘问题,迷宫问题,球和篮子的问题(google编程大赛) 各种算法中也会使用到递归,比如快速排序,归并排序,二分查找,分治算法等 将用栈解决的 ...

  8. iview报错[Vue warn]: Error in render: "TypeError: ctx.injections.tableRoot.$scopedSlots[ctx.props.column.slot] is not a function"

    原因是我使用了iview的<Table>组件,我给Table组件的columns中定义了4个含有slot的列,但是实际在<Table>中只使用了其中3个,导致的报错. 也就是说 ...

  9. js模拟自动化测试 -- 多用户登录

    1.核心登录提交方法 /** * 动态表单提交方法 * @param url{string}: 提交地址 * @param params{object}: 要提交的表单数据 **/ function ...

  10. eclipse调试openstack的nova代码

    前段时间一直在研究openstack的nova部分的代码.特别想知道,怎样用eclipse来调试代码.也在论坛上问了别人.无果.最后还是自己摸索出了出路. 以下写出自己探索之路.我是用devstack ...