-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] salt-ssh error when targetting IPs or hostnames directly #59033
Comments
I am having a hard time replicating this. I've targeted a host via IP address and hostname thats in a roster and one thats not in a roster, without issue. Any other information to help replicate this issue? |
I'm still able to replicate this issue. As I mentioned, I'm using the Ubuntu 16.04 desktop operating system.
This gives me The repo I'm working on is open source. The only notable thing I can think of between this and other installs is that I'm running command output``` $ salt-ssh 'ex1.example.com' test.ping [ERROR ] No matching targets found in roster. $ salt-ssh 'rhtest.dogshost.com' test.ping [ERROR ] An un-handled exception was caught by salt's global exception handler: AttributeError: 'str' object has no attribute 'get' Traceback (most recent call last): File "/usr/bin/salt-ssh", line 9, in load_entry_point('salt==3002.2', 'console_scripts', 'salt-ssh')() File "/usr/lib/python3/dist-packages/salt/scripts.py", line 479, in salt_ssh client.run() File "/usr/lib/python3/dist-packages/salt/cli/ssh.py", line 25, in run ssh = salt.client.ssh.SSH(self.config) File "/usr/lib/python3/dist-packages/salt/client/ssh/__init__.py", line 234, in __init__ self._expand_target() File "/usr/lib/python3/dist-packages/salt/client/ssh/__init__.py", line 373, in _expand_target if hostname in [host_id, roster_data[host_id].get("host")]: AttributeError: 'str' object has no attribute 'get' Traceback (most recent call last): File "/usr/bin/salt-ssh", line 9, in load_entry_point('salt==3002.2', 'console_scripts', 'salt-ssh')() File "/usr/lib/python3/dist-packages/salt/scripts.py", line 479, in salt_ssh client.run() File "/usr/lib/python3/dist-packages/salt/cli/ssh.py", line 25, in run ssh = salt.client.ssh.SSH(self.config) File "/usr/lib/python3/dist-packages/salt/client/ssh/__init__.py", line 234, in __init__ self._expand_target() File "/usr/lib/python3/dist-packages/salt/client/ssh/__init__.py", line 373, in _expand_target if hostname in [host_id, roster_data[host_id].get("host")]: AttributeError: 'str' object has no attribute 'get' $ salt-ssh '46.43.3.55' test.ping [ERROR ] An un-handled exception was caught by salt's global exception handler: AttributeError: 'str' object has no attribute 'get' Traceback (most recent call last): File "/usr/bin/salt-ssh", line 9, in load_entry_point('salt==3002.2', 'console_scripts', 'salt-ssh')() File "/usr/lib/python3/dist-packages/salt/scripts.py", line 479, in salt_ssh client.run() File "/usr/lib/python3/dist-packages/salt/cli/ssh.py", line 25, in run ssh = salt.client.ssh.SSH(self.config) File "/usr/lib/python3/dist-packages/salt/client/ssh/__init__.py", line 234, in __init__ self._expand_target() File "/usr/lib/python3/dist-packages/salt/client/ssh/__init__.py", line 373, in _expand_target if hostname in [host_id, roster_data[host_id].get("host")]: AttributeError: 'str' object has no attribute 'get' Traceback (most recent call last): File "/usr/bin/salt-ssh", line 9, in load_entry_point('salt==3002.2', 'console_scripts', 'salt-ssh')() File "/usr/lib/python3/dist-packages/salt/scripts.py", line 479, in salt_ssh client.run() File "/usr/lib/python3/dist-packages/salt/cli/ssh.py", line 25, in run ssh = salt.client.ssh.SSH(self.config) File "/usr/lib/python3/dist-packages/salt/client/ssh/__init__.py", line 234, in __init__ self._expand_target() File "/usr/lib/python3/dist-packages/salt/client/ssh/__init__.py", line 373, in _expand_target if hostname in [host_id, roster_data[host_id].get("host")]: AttributeError: 'str' object has no attribute 'get' ```The output of the first command |
I am having the same issue with 3003. After some debugging I have found that there are several possible outcomes. Using the minion's IP addresssalt-ssh using the IP address always fails with the above error. Using the minion's hostnameIn this case the behaviour is different depending if the minion is defined in the roster file and if it is or not resolved via the DNS (only direct resolution, not inverse)
So in the case the minion is defined in the roster it works but only if the host is not resolved by DNS or /etc/hosts. |
After some debugging I found the origin of the issue. The problem is when the roster file has one-line definitions of the type: This syntax worked in previous versions until #58163. Now the code in That is fine of course, and @Ch3LL did a good work and this is the correct call, but the problem is that now the resulta of I would propose to check the type and in case it is not and ordereddict just to use the value given, something like:
If you think it would be useful I can create a pull request. |
@javicacheiro thanks for taking the time to dive into this. That looks like an appropriate fix. Would you mind pushing that up as a PR with tests. I can help write tests too if needed. Just ping me on the PR when you push it up. |
Great, let's proceed that way. |
Did you want to push the PR or I can? |
@Ch3LL just created the PR, I would need some help with the tests. Looking at existing pytests/unit I see client/ssh and roster/test_dir.py, but I don't know if I miss something because I do not find the original tests for the expand_target function. |
There are a couple of expand_target tests here: tests/unit/client/test_ssh.py. Did you want me to write the tests? More than willing to just let me know. |
If you can it would be great!
|
Will do. I'll try to get to it this week or the beginning of next week :) |
Description
Running
salt-ssh
directly on an IP or hostname errors.Setup
Ubuntu 16.04 with only salt-ssh installed.
Steps to Reproduce the behavior
Returns the following output:
Expected behavior
This is how it works in version 3001.
It also works if I query the roster file instead of directly pointing at .
Versions Report
salt --versions-report
(Provided by running salt --versions-report. Please also mention any differences in master/minion versions.)Additional context
As I mentioned above, I can fix this by downgrading to salt-ssh version 3001.
The text was updated successfully, but these errors were encountered: