saltstack/salt — Issue #764: Running state.highstate on minions without any states causes a KeyError
Author: blast-hardcheese
Created: 2012-02-25 22:07:17+00:00
State: open

Getting started with states; I've got 5 minions on my network, I only defined a state for one of the minions. What I thought would happen when I ran salt \* state.highstate was it would only give me results for one minion, what ended up happening was:

Traceback (most recent call last):
File "/srv/virtualenv/bin/salt", line 18, in
main()
File "/srv/virtualenv/bin/salt", line 14, in main
client.run()
File "/srv/virtualenv/local/lib/python2.7/site-packages/salt/cli/__init__.py", line 270, in run
self._output_ret(ret, out)
File "/srv/virtualenv/local/lib/python2.7/site-packages/salt/cli/__init__.py", line 301, in _output_ret
printout(ret)
File "/srv/virtualenv/local/lib/python2.7/site-packages/salt/output.py", line 68, in __call__
for tname in sorted(data[host], key=lambda k: data[host][k]['__run_num__']):
File "/srv/virtualenv/local/lib/python2.7/site-packages/salt/output.py", line 68, in
for tname in sorted(data[host], key=lambda k: data[host][k]['__run_num__']):
KeyError: '__run_num__'

I traced down data[host], it contains:
{'no_|-states_|-states_|-None': {'comment': 'No states found for this minion', 'changes': {}, 'result': False, 'name': 'No States'}}

which is much better in terms of logging than a traceback ;)