如何在可以覆盖的支柱中设置基本值? [英] How to have base values in pillars that can be overridden?

查看:50
本文介绍了如何在可以覆盖的支柱中设置基本值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将所有 Salt 文件(支柱、状态、数据文件等)存储在一个 git 存储库中,以便可以在多个不同的部署中克隆该存储库.

I would like to store all Salt files (pillars, states, data files, etc.) in a git repository, so that this repository can be cloned on several different deployments.

然后我希望能够更改一些支柱设置的值,例如路径名或密码,但不编辑处于版本控制中的原始文件(即这些修改仅在本地进行,不一定是版本).

Then I would like to be able to change the value of some pillar settings, such as a pathname, or a password, but without editing the original file which is in version control (i.e. those modifications would be local only and not necessarily versioned).

我希望能够从原始存储库中提取新版本(例如添加新的支柱和状态定义)而不会丢失自定义值.

I would like to be able to pull new versions from the original repository (e.g. to add new pillar and state definitions) without losing the customized values.

例如基本"或默认"支柱文件将具有如下设置:

E.g. the "base" or "default" pillar file would have settings like:

service:
  dir: /var/opt/myservice
  username: myuser
  password: mypassword

我想在另一个文件中自定义一些设置,而不更改基本文件:

and I would like to customize some settings, in another file, without changing the base file:

service:
  dir: /mnt/data/myservice
  password: secret_password

修改后的设置应优先于基本/默认设置.

The modified settings should take precedence over the base / default ones.

是否可以通过使用环境(例如基本"环境和自定义"环境)来做到这一点?

Is it possible to do this by using environments (e.g. a "base" environment and a "custom" environment)?

或者也许通过包含这些自定义支柱文件?

Or perhaps by including these custom pillar files?

文档似乎表明覆盖支柱设置没有固定的顺序.

The documentation seems to indicate that there isn't a fixed order for overriding pillar settings.

推荐答案

让我首先建议一种将原始文件和自定义设置保存在 git 存储库中的方法.请参阅下文如何使用 git 之外的文件覆盖设置.

Let me first suggest a way where you keep the original file and the customized settings in the git repository. See below how to override setting with a file outside of git.

设置 Git Pillar

我假设所有文件都存储在一个 git 此处描述的支柱.我这里使用的是salt 2015.8版本的语法.

I assume all files are stored in a git pillar like described here. I am using the syntax of salt version 2015.8 here.

ext_pillar:
  - git:
    - master https://gitserver/git-pillar.git:
      - env: base

在您的 top.sls 文件中,您可以列出不同的 SLS 文件.它们将按照顶部文件中列出的顺序相互覆盖:

In your top.sls file you can list different SLS files. They will override each other in the order listed in the top file:

# top.sls
base:
  '*':
     standard
  '*qa'
     qaservers
  'hostqa':
     hostqaconfig

这将适用于所有服务器:

This will apply on all servers:

# standard.sls
test:
  setting1: A
  setting2: B

这将适用于名称以qa"结尾的所有服务器:

This will apply on all servers with the name ending with 'qa':

# qaservers.sls
test:
  setting2: B2

这将适用于名为hostqa"的服务器:

This will apply to the server with the name 'hostqa':

# hostqa.sls:
test:
  setting1: A2

命令 salt hostqa saltutil.refresh_pillarsalt hostqa pillar.data 然后将显示值 A2 和 B2,因为它们已全部合并在一起.

The commands salt hostqa saltutil.refresh_pillar and salt hostqa pillar.data will then show that the values A2 and B2 as they have all been merged together.

因为这不需要指定环境,所以我建议不要在这里使用环境.

As this works without specifying environments, I suggest not to use environments here.

覆盖 Git 之外的一些本地设置

要在本地覆盖您的某些设置,您可以添加另一个外部支柱.最简单的一个是 cmd_yaml,它将运行一个命令(此处:cat)并将输出与当前支柱合并:

To override some of your settings locally, you can add another external pillar. One of the most simple ones is cmd_yaml that will run a command (here: cat) and merge the output with the current pillar:

ext_pillar:
  - git:
    - master https://gitserver/git-pillar.git:
      - env: base
  - cmd_yaml: cat /srv/salt/local_override.sls

所有外部支柱都按照配置文件中列出的顺序执行.

All external pillars are executed in the order listed in the configuration file.

这篇关于如何在可以覆盖的支柱中设置基本值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆