KeyError的原因:运行salt state.highstate时出现'_errors'

时间:2018-01-08 22:26:12

标签: salt

将以下内容添加到我的minion支柱文件中后:

monit:
  services:
    - name: elasticsearch
      pid: /var/run/elasticsearch/elasticsearch.pid
      start_script: /etc/init.d/elasticsearch start
      start_script: /etc/init.d/elasticsearch stop
      port: 9200

当我尝试运行highstate时,我开始收到以下错误:

root@salt-master:/home/me# salt 'my-minion-id' state.highstate -t 300
my-minion-id:
  The minion function caused an exception: Traceback (most recent call last):
    File "/usr/lib/python2.7/dist-packages/salt/minion.py", line 1482, in _thread_return
      return_data = executor.execute()
    File "/usr/lib/python2.7/dist-packages/salt/executors/direct_call.py", line 28, in execute
      return self.func(*self.args, **self.kwargs)
    File "/usr/lib/python2.7/dist-packages/salt/modules/state.py", line 848, in highstate
      err += __pillar__['_errors']
    File "/usr/lib/python2.7/dist-packages/salt/utils/context.py", line 211, in __getitem__
      return self._dict()[key]
  KeyError: '_errors'

1 个答案:

答案 0 :(得分:1)

这个错误非常烦人,但事实证明这是因为我的支柱文件包含一个带有重复键的字典:

monit:
  services:
    - name: elasticsearch
      ...
      start_script: /etc/init.d/elasticsearch start
      start_script: /etc/init.d/elasticsearch stop
      ...

应该是:

monit:
  services:
    - name: elasticsearch
      ...
      start_script: /etc/init.d/elasticsearch start
      stop_script: /etc/init.d/elasticsearch stop
      ...

希望这有助于节省时间!