Prevent backtrace (KeyError) in ssh_known_hosts.present state

When using `test=true`, the `ssh_known_hosts.present` state will run
into a backtrace because of an KeyError. Prevent that.
```
An exception occurred in this state: Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/salt/state.py", line 1591, in call
    **cdata['kwargs'])
  File "/usr/lib/python2.7/site-packages/salt/states/ssh_known_hosts.py", line 122, in present
    config=config)
  File "/usr/lib/python2.7/site-packages/salt/modules/ssh.py", line 827, in check_known_host
    return ('exists' if fingerprint == known_host['fingerprint']
KeyError: 'fingerprint'
```
This commit is contained in:
Elias Probst 2015-11-23 00:39:44 +01:00
parent 1931870f26
commit 3f19c311e8
No known key found for this signature in database
GPG key ID: 82C512826511BADB

View file

@ -854,7 +854,7 @@ def check_known_host(user=None, hostname=None, key=None, fingerprint=None,
known_host = get_known_host(user, hostname, config=config, port=port)
if not known_host:
if not known_host or 'fingerprint' not in known_host:
return 'add'
if key:
return 'exists' if key == known_host['key'] else 'update'