我有以下SLS文件,试图在其中集中集中在小兵上进行静态路由:
mpls_routing.sls:
{% for interface in grains.get('ip_interfaces') %}
{% if interface != 'lo' %}
interface-{{interface}}:
file:
- name: /etc/sysconfig/network-scripts/route-{{interface}}
- managed
- source: salt://mpls_routing/mpls_routes.cfg
NetworkManager:
service.running:
- enable: True
- reload: True
- watch:
- file: /etc/sysconfig/network-scripts/route-{{interface}}
- require:
- interface-{{interface}}
{% endif %}
{% endfor %}`
当我尝试使用state编译此SLS文件时,show_sls mpls_routing在一个小兵上编译正常,而在另一个小兵上编译失败。
salt -v -L 'minion1,minon2' state.show_sls mpls_routing
minion1:
----------
NetworkManager:
----------
__env__:
base
__sls__:
mpls_routing
service:
|_
----------
enable:
True
|_
----------
reload:
True
|_
----------
watch:
|_
----------
file:
/etc/sysconfig/network-scripts/route-ens192
|_
----------
require:
- interface-ens192
- running
|_
----------
order:
10001
interface-ens192:
----------
__env__:
base
__sls__:
mpls_routing
file:
|_
----------
name:
/etc/sysconfig/network-scripts/route-ens192
- managed
|_
----------
source:
salt://mpls_routing/mpls_routes.cfg
|_
----------
order:
10000
minion2:
- Rendering SLS 'base:mpls_routing' failed: while constructing a mapping
in "<unicode string>", line 6, column 1:
interface-ens192:
^
found conflicting ID 'NetworkManager'
in "<unicode string>", line 31, column 1:
NetworkManager:
^
ERROR: Minions returned with non-zero exit code
我不确定为什么第二个奴才失败了。错误中的接口名称表明jinja模板获取的接口名称正确。即使盐仅针对minion2,sls也无法编译。我不确定这里发生了什么或如何解决?
答案 0 :(得分:0)
在上述Gijs的评论之后,回答我自己的问题导致了我的疑问。 sls文件中的第二个对象
NetworkManager:
在minion2上重复执行,minion2具有由grains返回的多个ip_interface值。这意味着sls具有相同字典键的两个副本。我将sls文件更新为:
{% for interface in grains.get('ip_interfaces') %}
{% if interface != 'lo' %}
interface-{{interface}}:
file:
- name: /etc/sysconfig/network-scripts/route-{{interface}}
- managed
- source: salt://mpls_routing/mpls_routes.cfg
NetworkManager-{{interface}}:
service.running:
- name: NetworkManager
- enable: True
- reload: True
- watch:
- file: /etc/sysconfig/network-scripts/route-{{interface}}
- require:
- interface-{{interface}}
{% endif %}
{% endfor %}
解决了该问题。