我正在使用Salt 2018.3.2以及/srv/pillar/mypillar.sls中的以下支柱数据
#!yaml
mypillar:
some_key: some_value
并尝试在以下状态文件/srv/salt/orch/mypillar.sls中使用它
write-pillar-file:
file.managed:
- name: /tmp/mypillar.txt
- contents_pillar: mypillar
如果被称为状态,它工作正常:
$ salt'localhost'state.apply orch.mypillar
如果被称为orchestrate runner,则无效:
$ salt-run state.orchestrate orch.mypillar
[INFO ] Loading fresh modules for state activity
[INFO ] Fetching file from saltenv 'base', ** done ** 'orch/mypillar.sls'
[INFO ] Running state [/tmp/mypillar.txt] at time 18:32:03.120348
[INFO ] Executing state file.managed for [/tmp/mypillar.txt]
[ERROR ] Pillar mypillar does not exist
[INFO ] Completed state [/tmp/mypillar.txt] at time 18:32:03.122809 (duration_in_ms=2.461)
如果我通过命令行传递支柱,它可以工作,但我想从文件系统访问支柱。这不可能吗?任何建议赞赏!
我在github上发布了相同的问题,并得到了关于支柱信息与奴才相关的建议,这意味着盐运行无法访问支柱信息,因为它运行时没有minion环境。一个解决方法是显式查询这样的支柱信息(在我的例子中,我使用'localhost'作为我的salt master的minion ID):
{% set pillardata = salt.saltutil.runner('pillar.show_pillar', kwarg={'minion': 'localhost'}) %}
write-pillar-file:
file.managed:
- name: /tmp/mypillar.txt
- contents:
- {{ pillardata['mypillar']['some_key'] }}