代码之家  ›  专栏  ›  技术社区  ›  Jorge

使用支柱中定义的角色的目标奴才

  •  0
  • Jorge  · 技术社区  · 7 年前

    在/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 %}
    
    1 回复  |  直到 7 年前
        1
  •  0
  •   Andrew    7 年前

    根据 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
    

    毕竟,这是最高的目标。如果你的小人身份证不适合地球人,那就把节点群作为一种选择。