saltstack/salt — pull request #14620 by sontek (2014-07-30 05:29:35+00:00)
Title: Handle no roster file gracefully

Before this PR:

```
salt-ssh -c /home/sontek/src/salttest/smstack/etc/ '127.0.0.1' test.ping
[ERROR ] An un-handled exception was caught by salt's global exception handler:
IOError: [Errno 2] No such file or directory: ''
Traceback (most recent call last):
File "/home/sontek/venvs/salttest/bin/salt-ssh", line 9, in
load_entry_point('salt==2014.7.0-567-g6dae7e8', 'console_scripts', 'salt-ssh')()
File "/home/sontek/src/salttest/salt/salt/scripts.py", line 252, in salt_ssh
client.run()
File "/home/sontek/src/salttest/salt/salt/cli/__init__.py", line 461, in run
ssh = salt.client.ssh.SSH(self.config)
File "/home/sontek/src/salttest/salt/salt/client/ssh/__init__.py", line 181, in __init__
self.tgt_type)
File "/home/sontek/src/salttest/salt/salt/roster/__init__.py", line 52, in targets
targets.update(self.rosters[f_str](tgt, tgt_type))
File "/home/sontek/src/salttest/salt/salt/roster/ansible.py", line 131, in targets
imatcher = Inventory(tgt, tgt_type='glob', inventory_file=hosts)
File "/home/sontek/src/salttest/salt/salt/roster/ansible.py", line 188, in __init__
with salt.utils.fopen(inventory_file) as config:
File "/home/sontek/src/salttest/salt/salt/utils/__init__.py", line 1110, in fopen
fhandle = open(*args, **kwargs)
IOError: [Errno 2] No such file or directory: ''
```

and if you removed the ansible plugin:

```
salt-ssh -c /home/sontek/src/salttest/smstack/etc/ '*' test.ping
[ERROR ] An un-handled exception was caught by salt's global exception handler:
SaltRenderError: Unable to render any roster.
Traceback (most recent call last):
File "/home/sontek/venvs/salttest/bin/salt-ssh", line 9, in
load_entry_point('salt==2014.7.0-567-g6dae7e8', 'console_scripts', 'salt-ssh')()
File "/home/sontek/src/salttest/salt/salt/scripts.py", line 252, in salt_ssh
client.run()
File "/home/sontek/src/salttest/salt/salt/cli/__init__.py", line 461, in run
ssh = salt.client.ssh.SSH(self.config)
File "/home/sontek/src/salttest/salt/salt/client/ssh/__init__.py", line 181, in __init__
self.tgt_type)
File "/home/sontek/src/salttest/salt/salt/roster/__init__.py", line 61, in targets
raise salt.exceptions.SaltRenderError('Unable to render any roster.')
SaltRenderError: Unable to render any roster.
Traceback (most recent call last):
File "/home/sontek/venvs/salttest/bin/salt-ssh", line 9, in
load_entry_point('salt==2014.7.0-567-g6dae7e8', 'console_scripts', 'salt-ssh')()
File "/home/sontek/src/salttest/salt/salt/scripts.py", line 252, in salt_ssh
client.run()
File "/home/sontek/src/salttest/salt/salt/cli/__init__.py", line 461, in run
ssh = salt.client.ssh.SSH(self.config)
File "/home/sontek/src/salttest/salt/salt/client/ssh/__init__.py", line 181, in __init__
self.tgt_type)
File "/home/sontek/src/salttest/salt/salt/roster/__init__.py", line 61, in targets
raise salt.exceptions.SaltRenderError('Unable to render any roster.')
salt.exceptions.SaltRenderError: Unable to render any roster.
```

Now it returns:
```
salt-ssh -c /home/sontek/src/salttest/smstack/etc/ '*' test.ping
Unable to render any roster.
```

and

```
salt-ssh -c /home/sontek/src/salttest/smstack/etc/ '127.0.0.1' test.ping
Permission denied for host 127.0.0.1, do you want to deploy the salt-ssh key? (password required):
[Y/n] n
127.0.0.1:
----------
retcode:
255
stderr:
Permission denied (publickey,password).

stdout:
```