seantis / suitable

An Ansible API for humans.
GNU General Public License v3.0
171 stars 23 forks source link

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

Open pylSER opened 5 years ago

pylSER commented 5 years ago

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 commented 5 years ago

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

href commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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 root@127.0.0.1 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?

href commented 5 years ago

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