Hi,
is the uri module a curl substitute?
I ask because if, on the command line, I run curl, I get the expected json output from a tomcat rest application. In the logs is a 200 result.
But if I run the same in uri then …
TASK [test with curl type command] *********************************************
fatal: [localhost]: FAILED! => {“changed”: false, “content”: “”, “failed”: true, “msg”: “Status code was not [200]: Connection failure: timed out”, “redirected”: false, “status”: -1, “url”: “http://centos7-ansible:8080/heroes/heroes”}
What am I doing wrong?
Regards,
Could it be that the host blocks outgoing HTTP traffic, and that you
have some proxy environment variable set in your interactive terminal
to reach HTTP content?
If that is the case, you should make Ansible aware of that:
http://docs.ansible.com/ansible/playbooks_environment.html
Dick
It'd be worth checking if a command: task using curl works.
If not it's probably a shell environment (proxy?) issue.
I've seen curl work where get_url: / uri: doesn't if you are hitting an SNI
endpoint, my workaround is a command: task. Issue here:
https://github.com/ansible/ansible-modules-core/issues/1716
many thanks to both of you for the replies.
I tried both shell and command modules with the curl command and a
curl: (7) Failed connect to centos7-ansible:8080; Connection refused"
Not sure why the connection would be refused as there. The previous task in ansible is to start tomcat so would it be too soon to accept requests? Tried adding a pause and that worked with a command module but not the uri module. But curl does take a long time to run whereas outside of anisble it is instant.
I did increase the timeout value on uri and that did allow it to complete OK.
This is all running on the same VM so there should not be proxy issues.
Instead of pause you could use until: so it retries until you get 200.
https://docs.ansible.com/ansible/playbooks_loops.html#do-until-loops
Can you use wait_for to check if a web server application return status code 200?
If so how? It's not clear to me after reading the documentation.
Can you use wait_for to check if a web server application return status
code 200?
If so how? It’s not clear to me after reading the documentation.
I haven’t tried, but I thought search_regex: ‘HTTP/1.1 200 OK’ or something similar
Cheers,
Paul
I would check to see if this is resolving to an IPv6 address at one end
and listening on IPv4 only at the other, or some variation on that.
Try doing that with `curl -v4sk ...` (force ipv4, verbose output, silent
response, ignore SSL certificate chain) and see whether that provides
more info. Sharing the output here may get you the info you need.
Either way, the next logical step here is to run a packet capture (ngrep
or tcpdump for example) which will probably make it very obvious what is
failing.
A+
Dave
I was thinking of a wait_for: task *before* the uri: check, just to give tomcat
enough time to start a http connector
(I don't think wait_for on its own would work, as there's no option
to send a GET to the port).
The more I think about it, the more I prefer your idea; I've seen plenty of WARs
that take ages to fire up after the port is open.