uri module and curl

1 071 vues
Accéder directement au premier message non lu

norricorp

non lue,
28 févr. 2017, 04:42:1028/02/2017
à Ansible Project
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 ...
    - name: test with curl type command
      uri:
         url: http://centos7-ansible:8080/heroes/heroes

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,

Dick Visser

non lue,
28 févr. 2017, 06:07:0528/02/2017
à ansible...@googlegroups.com
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
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ansible-proje...@googlegroups.com.
> To post to this group, send email to ansible...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/f4133ed5-8800-4c8c-8304-de095a245c7c%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
Dick Visser
Sr. System & Network Engineer
GÉANT

Want to join us? We're hiring: https://www.geant.org/jobs

Dick Davies

non lue,
28 févr. 2017, 06:45:2528/02/2017
à ansible list
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

norricorp

non lue,
28 févr. 2017, 08:38:4828/02/2017
à Ansible Project,di...@hellooperator.net
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.


Kai Stian Olstad

non lue,
28 févr. 2017, 08:56:4928/02/2017
à ansible...@googlegroups.com
On 28.02.2017 14:38, norricorp wrote:
> 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.

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

--
Kai Stian Olstad

Paul Tötterman

non lue,
1 mars 2017, 05:29:2701/03/2017
à Ansible Project,ansible-pr...@olstad.com
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

Kai Stian Olstad

non lue,
1 mars 2017, 08:06:1601/03/2017
à ansible...@googlegroups.com
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.

--
Kai Stian Olstad

Paul Tötterman

non lue,
1 mars 2017, 08:16:3401/03/2017
à Ansible Project,ansible-pr...@olstad.com
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 

Dave Cottlehuber

non lue,
2 mars 2017, 14:22:5002/03/2017
à ansible...@googlegroups.com
On Tue, 28 Feb 2017, at 14:38, norricorp wrote:
> 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"

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

Dick Davies

non lue,
2 mars 2017, 15:48:2502/03/2017
à ansible list
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.

On 1 March 2017 at 13:05, Kai Stian Olstad
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ansible-proje...@googlegroups.com.
> To post to this group, send email to ansible...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/9099b9c07a63166dfe4372a01916d91b%40olstad.com.
Répondre à tous
Répondre à l'auteur
Transférer
0 nouveau message