Skip to content
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

Connection to the localhost fails silently, resulting in the wrong return code. #38

Open
pylSER opened this issue Oct 13, 2019 · 5 comments
Labels

Comments

@pylSER
Copy link

pylSER commented Oct 13, 2019

HI, I am using

python 3.7.4 suitable = "^0.16.0" ansible 2.8.5

And I found that the return code is not correct when there are multi hosts:

say I would like to check if a directory exists on every host:

cmd = "test -d  /the/dir/does/not/exist/on/some/of/the/hosts"
res = Api(iplist, remote_user="root", host_key_checking=False, ignore_errors=True).shell(cmd)
for ip in iplist:
    res_code = res.rc(ip)
    # all res code will be 0

Am I using it in a wrong manner? Or it is a bug?

@pylSER
Copy link
Author

pylSER commented Oct 13, 2019

By the way, one of the host in iplist is '127.0.0.1'
No '127.0.0.1', no problem.

@pylSER pylSER changed the title return code is not correct when there are multi hosts return code is not correct when there are multi hosts(including 127.0.0.1) Oct 13, 2019
@href
Copy link
Contributor

href commented Oct 14, 2019

I don't see an error on your side, nor one on Suitable's. I tried your script on some of my own hosts and the results are correct (some 1s, some 0s, for a folder that only exists on some hosts).

You can try and pass verbosity='info' to the Api class constructor and wade through the heaps of log output to find out if something is wrong. You can also double check your test call by just using ssh:

ssh foo test -d /foo/bar && echo 'exists' || echo 'missing'

Because ultimately that's what happens behind the scenes.

@href
Copy link
Contributor

href commented Oct 14, 2019

Oh also, can you try to instantiate the api with Api(connection='smart'). You're saying that without 127.0.0.1 there's no problem, so maybe there's an issue with how Suitable sets the connection if not specifically configured.

@pylSER
Copy link
Author

pylSER commented Oct 14, 2019

HI 'Moss',

After applying connection='smart', I found the error: suitable.errors.UnreachableError: 127.0.0.1 could not be reached

And I found ssh [email protected] on my machine requires password.

So it is basically my problem, but without applying connection='smart', all res code would be 0 and there will be no exceptions, which is not intuitive, isn't it?

@pylSER pylSER changed the title return code is not correct when there are multi hosts(including 127.0.0.1) return code is not correct when there are multi hosts(including unreachable hosts) Oct 14, 2019
@href
Copy link
Contributor

href commented Oct 14, 2019

Definitely not, I'll edit the title of this and leave it open as a bug.

@href href changed the title return code is not correct when there are multi hosts(including unreachable hosts) Connection to the localhost fails silently, resulting in the wrong return code. Oct 14, 2019
@href href added the bug label Oct 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants