Search code examples
salt-project

Cause of KeyError: '_errors' when running salt state.highstate


After adding the following to my minion pillar file:

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

I started receiving the following error when I tried to run 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'

Solution

  • This error was quite annoying, but it turns out that it was because my pillar file contained a dictionary with duplicate keys:

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

    which should have instead been:

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

    Hope this helps save someone time!