URI Module fails POST but CURL succeds as shell

2,399 views
Skip to first unread message

sve...@oration.com

unread,
Jul 6, 2015, 9:46:59 AM7/6/15
to ansible...@googlegroups.com
I am getting a connection refused socket error :111 when using get_uri module for POST of a zip file to a url . If i use curl command on shell the task runs without error. How can i fix this issue?

Romeo Theriault

unread,
Jul 6, 2015, 10:06:51 AM7/6/15
to ansible...@googlegroups.com
What does it show you when you run it in verbose mode?

On Sun, Jul 5, 2015 at 11:53 PM, <sve...@oration.com> wrote:
I am getting a connection refused socket error :111 when using get_uri module for POST of a zip file to a url . If i use curl command on shell the task runs without error. How can i fix this issue?

--
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/88f8e809-9ce6-4e7a-ad43-39fc3f78abbf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Romeo

sve...@oration.com

unread,
Jul 8, 2015, 9:37:43 PM7/8/15
to ansible...@googlegroups.com
Hello, this is the error I get , when i run it in verbose mode.
TASK: [Curl to post to oabc] *******************************************
<10.1.3.163> ESTABLISH CONNECTION FOR USER: ubuntu
<10.1.3.163> EXEC ssh -C -tt -vvv -o ControlMaster=auto -o ControlPersist=60s -o ControlPath="/home/vagrant/.ansible/cp/ansible-ssh-%h-%p-%r" -o IdentityFile="/home/vagrant/ahafasfhsalf_Dev.pem" -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=ubuntu -o ConnectTimeout=120 10.1.3.163 /bin/bash -c 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1436405328.75-170552693510188 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1436405328.75-170552693510188 && echo $HOME/.ansible/tmp/ansible-tmp-1436405328.75-170552693510188'
<10.1.3.163> PUT /tmp/tmpGByUla TO /home/ubuntu/.ansible/tmp/ansible-tmp-1436405328.75-170552693510188/uri
<10.1.3.163> EXEC ssh -C -tt -vvv -o ControlMaster=auto -o ControlPersist=60s -o ControlPath="/home/vagrant/.ansible/cp/ansible-ssh-%h-%p-%r" -o IdentityFile="/home/vagrant/ahafasfhsalf_Dev.pem" -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=ubuntu -o ConnectTimeout=120 10.1.3.163 /bin/bash -c 'sudo -k && sudo -H -S -p "[sudo via ansible, key=szyrygobamhtrmdhebttkjwsmjgkyuhc] password: " -u root /bin/bash -c '"'"'echo BECOME-SUCCESS-szyrygobamhtrmdhebttkjwsmjgkyuhc; LANG=C LC_CTYPE=C /usr/bin/python /home/ubuntu/.ansible/tmp/ansible-tmp-1436405328.75-170552693510188/uri; rm -rf /home/ubuntu/.ansible/tmp/ansible-tmp-1436405328.75-170552693510188/ >/dev/null 2>&1'"'"''
failed: [10.1.3.163] => (item=abcd_v3.0_Monthly_Master_20150701.ZIP) => {"failed": true, "item": "abcd_v3.0__20150701.ZIP"}
msg: Socket error: [Errno 111] Connection refused to http://localhost/api/v1.0/abcd?abcdZipFile=abcd_v3.0__20150701.ZIP
...ignoring

Brian Coca

unread,
Jul 8, 2015, 10:35:37 PM7/8/15
to ansible...@googlegroups.com
where is the api running? can you show the curl command that succeeds?
where do you run it from?


--
Brian Coca

sve...@oration.com

unread,
Jul 9, 2015, 2:21:01 PM7/9/15
to ansible...@googlegroups.com
The playbook below works with CURL in SHELL but not URI
---
- hosts: 10.1.3.163
  user: ubuntu
  sudo: yes
  vars_files:
     - vars.yml
  tasks:
    - name: Run curl

sve...@oration.com

unread,
Jul 9, 2015, 2:21:27 PM7/9/15
to ansible...@googlegroups.com
The API is running on 10.1.3.163

Romeo Theriault

unread,
Jul 9, 2015, 2:59:49 PM7/9/15
to ansible...@googlegroups.com
It looks like you're missing the port (9004) in the URI call. Which would make sense because it's getting a "connection refused" socket level error.

--
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.

For more options, visit https://groups.google.com/d/optout.



--
Romeo

sve...@oration.com

unread,
Jul 9, 2015, 3:50:12 PM7/9/15
to ansible...@googlegroups.com
I added the port and tested again. here is the error I get.

####################

failed: [10.1.3.163] => (item=abcd_v3.0_Monthly_Master_20150701.ZIP) => {"content": "", "content_length": "0", "failed": true, "item": "abcd_v3.0_Monthly_Master_20150701.ZIP", "redirected": false, "status": 500}
msg: Status code was not [200]
...ignoring

#################

This is the task in the playbook

  - name: Curl to post to xxxx
      uri:
        method: POST
        status_code: 200
      with_items: abcdUPLOAD.stdout_lines
      register: status
      ignore_errors: True
    - debug: var=status


On Monday, July 6, 2015 at 6:46:59 AM UTC-7, sve...@oration.com wrote:

Romeo Theriault

unread,
Jul 9, 2015, 5:17:48 PM7/9/15
to ansible...@googlegroups.com
Getting closer. 500 is an internal server error. Do you have access to the server logs? Also, run the playbook with --verbose and set return_content=yes on the task.

I'd also wrap the url in doublequotes. I'm guess the url string is getting messed up somehow.



--
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.

For more options, visit https://groups.google.com/d/optout.



--
Romeo

Toshio Kuratomi

unread,
Jul 9, 2015, 6:15:33 PM7/9/15
to ansible...@googlegroups.com
On Jul 9, 2015 12:50 PM, <sve...@oration.com> wrote:
I added the port and tested again. here is the error I get.

####################

failed: [10.1.3.163] => (item=abcd_v3.0_Monthly_Master_20150701.ZIP) => {"content": "", "content_length": "0", "failed": true, "item": "abcd_v3.0_Monthly_Master_20150701.ZIP", "redirected": false, "status": 500}
msg: Status code was not [200]
...ignoring

#################

This is the task in the playbook

  - name: Curl to post to xxxx
      uri:
        method: POST
        status_code: 200
      with_items: abcdUPLOAD.stdout_lines
      register: status
      ignore_errors: True
    - debug: var=status

Status code 500 is an internal server error which means the application you're talking had a problem.  Might check the logs for the application to see if it reported why it couldn't handle the request.

I also note that the filename that the uri module is trying to POST is different from the filename in your curl.  That might be a clue as well.

-Toshio 
Reply all
Reply to author
Forward
0 new messages