如何从另一个支柱文件中导入数据? [英] How do I import data in one pillar file from another?

查看:40
本文介绍了如何从另一个支柱文件中导入数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

情况:我们有多个盐配方,其中包含某些支柱配置选项,在我们的环境中,这些选项是相同的.例如,它们对上游服务使用相同的 URL.我们希望避免在多个支柱位置复制这些值(我们想要一个单一的事实点),但我们不想以它们共享支柱键的方式编写公式(正交对灵魂有益).

The situation: We have multiple salt formulas with certain pillar-configured options that, in our environment, are identical. For example, they use the same URL for an upstream service. We would like to avoid duplicating these values in multiple pillar locations (we want a single point of truth), but we don't want to write the formulas in such a manner that they share pillar keys (orthoganality is good for the soul).

在我看来,正确的方法是拥有一个包含共享"值的支柱文件,然后将它们从那里导入到特定于公式的支柱文件中的适当位置.例如:

It seems to me that the right way to do this is to have one pillar file with the "shared" values and import them from there to the appropriate locations in the formula-specific pillar files. For example:

# pillar/shared.sls
upstream: https://example.com/youarehere

# pillar/formula1.sls
{%- from shared import upstream %}
formula1:
  upstream_uri: {{ upstream }}

# pillar/formula2.sls
{%- from shared import upstream %}
formula2:
  upstream_url: {{ upstream }}

# and so on...

当然,这不像写的那样工作.正确的做法是什么?

Of course, that doesn't work as written. What's the correct way to do it?

推荐答案

试试这个:

支柱/shared.sls

upstream: https://example.com/youarehere

支柱/formula1.sls

{% import_yaml "shared.sls" as defaults %}
formula1:
  upstream_uri: {{ defaults.upstream }}

支柱/formula2.sls

{% import_yaml "shared.sls" as defaults %}
formula2:
  upstream_url: {{ defaults.upstream }}

这篇关于如何从另一个支柱文件中导入数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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