【问题标题】:Target minions using roles defined in pillar使用在支柱中定义的角色定位奴才
【发布时间】:2018-07-24 11:53:57
【问题描述】:

在 /srv/salt/pillar/servers.sls 中有这个结构

servers:
# Monitors
  - m1:
    - roles: [ monitor ]
    - ips: [ 192.168.0.1 ]
  - b2:
    - roles: [ monitor ]
    - ips: [ 192.168.0.2 ]
# BPs
  - w2:
    - roles:
      - webserver:
        - type: [ apache ]
    - ips: [ 192.168.0.3 ]

我想在我的 top.sls 文件中使用该信息。

如何选择例如具有监控角色的服务器?或者是 apache 类型的服务器?

base:
  '*':
    - common
  {% Filter the servers that have the rol monitor %}
    - mon
  {% endfor %}
  {% Filter the servers that have the type apache %}
    - web_apache
  {% endfor %}

【问题讨论】:

    标签: salt-stack


    【解决方案1】:

    根据the documentation,这是可行的:

    # Any minion for which the pillar key 'somekey' is set and has a value
    # of that key matching 'abc' will have the 'xyz.sls' state applied.
    
    'somekey:abc':
        - match: pillar
        - xyz
    

    ...但我认为它不适合您的用例。您的“角色”项目是一个列表,我猜您想要更像“如果该列表中的任何项目是“监视器”,则应用状态 X。这样不会起作用。

    我很确定你的方法有缺陷。与其使用支柱文件将服务器映射到角色并从那里映射到状态,不如直接在顶部进行:

    base:
      '*':
        - common
      'm*':
        - mon
      'w*':
        - web_apache
    

    毕竟,这是 top 的预期目的。如果您的 minion ID 不能很好地适应 glob,请查看节点组作为替代方案。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-02-04
      • 1970-01-01
      • 1970-01-01
      • 2018-08-10
      • 2021-07-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多