使用盐的输出作为 SLS 状态或支柱的输入? [英] Using the output of salt to be used as input for an SLS state or pillar?
问题描述
例如,我想找到所有带有某个标签的节点,获取它们的 IP 地址,然后生成一个配置文件分发给这些节点.
For example, I want to find all nodes with a certain tag, grab their IP address, then generate a config file to distribute to those nodes.
一个用例可能是一个需要了解每个其他节点的数据库,但可以随时添加和删除节点.
A use case might be a database that needs to know about every other node, but can have nodes added and removed at any time.
推荐答案
您可以使用 Salt Mine 来完成.首先,将此配置分发给所有 Minion:
You can use Salt Mine to do it. First, distribute this configuration to all the Minions:
mine_functions:
grains.item:
- roles
- fqdn_ip4
使用该配置,每个 Minion 都会将这两个 Grain 发布给所有其他 Minion.有关我的更多详细信息此处.
With that configuration, every Minion will publish those two grains to all other minions. More details about Mine here.
现在,我们可以创建一个文件,所有名称都为 role=db.
Now, we can create a file with all the names with role=db.
/tmp/mydbhosts:
file:
- managed
- source: salt://example/myhosts
- template: mako
模板示例/myhosts:
The template example/myhosts:
% for minion, peer_grains in salt['mine.get']('*', 'grains.items').items():
% if "db" in peer_grains["role"]:
minion peer_grains["fqdn_ip4"]
% endif
% endfor
这篇关于使用盐的输出作为 SLS 状态或支柱的输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!