How do I import data in one pillar file from another?

丶灬走出姿态 提交于 2019-12-13 15:26:40

问题


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?


回答1:


Try this:

pillar/shared.sls

upstream: https://example.com/youarehere

pillar/formula1.sls

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

pillar/formula2.sls

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


来源:https://stackoverflow.com/questions/32748964/how-do-i-import-data-in-one-pillar-file-from-another

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!