# New URI module from Romeo Theriault

**URL:** <https://forum.ansible.com/t/new-uri-module-from-romeo-theriault/12370>\
**Category:** Ansible Project\
**Created:** [February 16, 2013, 11:50pm UTC](https://forum.ansible.com/t/new-uri-module-from-romeo-theriault/12370 "2013-02-16T23:50:27Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [February 16, 2013, 11:50pm UTC](https://forum.ansible.com/t/new-uri-module-from-romeo-theriault/12370/1 "2013-02-16T23:50:27Z")

</div>

Romeo Theriault wrote an EXCELLENT module for interacting with web  
services, and I've pushed it, and the docs on it are now up on the  
docsite.

It's called "uri".

Unfortunately the examples kind of ate it when using our docsite  
module formatter (produced some weird markup), so there aren't a lot  
of examples online yet.

You should try it out anyway.

It can be used in combination with "fail" and "register" and "when"  
and the like to do really basic tests for web services, and it can  
even log into forms, use register to save a cookie, and then submit  
other requests.

You can even use it submit JIRA tickets.

(Actually what I am thinking is eventually we start including more  
examples in the examples directory, and the docsite can just link to  
them).

Check it out!

-Michael

---

<div class="post-metadata">

**Author:** ![Romeo\_Theriault](https://avatars.discourse-cdn.com/v4/letter/r/839c29/32.png) [@Romeo\_Theriault](https://forum.ansible.com/u/Romeo_Theriault)\
**Post date:** [February 17, 2013, 12:51am UTC](https://forum.ansible.com/t/new-uri-module-from-romeo-theriault/12370/2 "2013-02-17T00:51:05Z")

</div>

Thanks Michael!

Until we get the examples formatting straightened out I figured I’d post the examples they will show here so people can get a taste of how it works:

```auto
# Check that you can connect to a page and it returns a status 200"
action: uri url=[http://www.awesome.com](http://www.awesome.com) method=GET"

# Check that a page returns a status 200 and fail if the word AWESOME is not in the page contents.

```

```auto

action: uri url=[http://www.awesome.com](http://www.awesome.com) method=GET return_content=yes
register: webpage

action: fail
when_string: '"AWESOME" not in "${webpage.content}"'

     
# "Create a JIRA issue."
action: uri url=[https://your.jira.server.com/rest/api/2/issue/](https://your.jira.server.com/rest/api/2/issue/) method=POST user=your_username password=your_pass body='$FILE(issue.json)' force_basic_auth=yes status_code=201 HEADER_Content-Type="application/json"

     
# Login to a form based webpage, then use the cookie that got returned to access the app in later tasks.

action: uri url=[https://your.form.based.auth.app.com/index.php](https://your.form.based.auth.app.com/index.php) method=POST body="name=your_username&password=your_password&enter=Sign%20in" status_code=302 HEADER_Content-Type="application/x-www-form-urlencoded"

register: login

action: uri url=[https://your.form.based.auth.app.com/dashboard.php](https://your.form.based.auth.app.com/dashboard.php) method=GET return_content=yes HEADER_Cookie="${login.set_cookie}"

```

```auto

```

---

<div class="post-metadata">

**Author:** ![Lorin\_Hochstein1](https://avatars.discourse-cdn.com/v4/letter/l/ce73a5/32.png) [@Lorin\_Hochstein1](https://forum.ansible.com/u/Lorin_Hochstein1)\
**Post date:** [February 17, 2013, 12:56am UTC](https://forum.ansible.com/t/new-uri-module-from-romeo-theriault/12370/3 "2013-02-17T00:56:57Z")

</div>

Romeo:

Which machine are the requests made from, the remote host or the local machine that runs Ansible?

Lorin

---

<div class="post-metadata">

**Author:** ![Romeo\_Theriault](https://avatars.discourse-cdn.com/v4/letter/r/839c29/32.png) [@Romeo\_Theriault](https://forum.ansible.com/u/Romeo_Theriault)\
**Post date:** [February 17, 2013, 1:00am UTC](https://forum.ansible.com/t/new-uri-module-from-romeo-theriault/12370/4 "2013-02-17T01:00:51Z")

</div>

The remote machine unless you specify the task as a 'delegate\_to' or  
'local\_action' type task.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [February 17, 2013, 1:01am UTC](https://forum.ansible.com/t/new-uri-module-from-romeo-theriault/12370/5 "2013-02-17T01:01:06Z")

</div>

> Which machine are the requests made from, the remote host or the local  
> machine that runs Ansible?

There is no connection plugin involved.

If you use local\_action, they are local, if not, they are not.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [February 17, 2013, 1:02am UTC](https://forum.ansible.com/t/new-uri-module-from-romeo-theriault/12370/6 "2013-02-17T01:02:38Z")

</div>

> Thanks Michael!
> 
> Until we get the examples formatting straightened out I figured I'd post the  
> examples they will show here so people can get a taste of how it works:

Thanks, I think "make docs" were fine but it was evident issues came  
up with "make webdocs" when they produced weirdness in the rst files  
that Sphinx did not like.

If you want to try to fix those, that would be great, and I'll take them.

I am herding too many other random things 🙂

---

<div class="post-metadata">

**Author:** ![Romeo\_Theriault](https://avatars.discourse-cdn.com/v4/letter/r/839c29/32.png) [@Romeo\_Theriault](https://forum.ansible.com/u/Romeo_Theriault)\
**Post date:** [February 17, 2013, 1:05am UTC](https://forum.ansible.com/t/new-uri-module-from-romeo-theriault/12370/7 "2013-02-17T01:05:32Z")

</div>

Thanks for the pointer and absolutely, I'll work on getting it  
straightened out this weekend and sending a PR.

Thanks,

---

<div class="post-metadata">

**Author:** ![Edgars](https://avatars.discourse-cdn.com/v4/letter/e/f17d59/32.png) [@Edgars](https://forum.ansible.com/u/Edgars)\
**Post date:** [October 7, 2013, 11:07am UTC](https://forum.ansible.com/t/new-uri-module-from-romeo-theriault/12370/8 "2013-10-07T11:07:36Z")

</div>

Hi

Is it possible to define two status\_codes? For instance I have webpage which can return status code 200 or status code 301 and both are ok. How can i tell uri module to accept both?

thanks  
Edgars

svētdiena, 2013. gada 17. februāris 00:50:27 UTC+1, Michael DeHaan rakstīja:

---

<div class="post-metadata">

**Author:** ![Edgars](https://avatars.discourse-cdn.com/v4/letter/e/f17d59/32.png) [@Edgars](https://forum.ansible.com/u/Edgars)\
**Post date:** [October 7, 2013, 11:38am UTC](https://forum.ansible.com/t/new-uri-module-from-romeo-theriault/12370/9 "2013-10-07T11:38:09Z")

</div>

PR#4383

Edgars

svētdiena, 2013. gada 17. februāris 00:50:27 UTC+1, Michael DeHaan rakstīja:

---

<div class="post-metadata">

**Author:** ![Nick\_Maslov](https://avatars.discourse-cdn.com/v4/letter/n/7ab992/32.png) [@Nick\_Maslov](https://forum.ansible.com/u/Nick_Maslov)\
**Post date:** [October 8, 2013, 1:17pm UTC](https://forum.ansible.com/t/new-uri-module-from-romeo-theriault/12370/10 "2013-10-08T13:17:20Z")

</div>

Hi,

Can someone point me to a way of using this module with, say Openstack Keystone?

I sending my login/password to IP:35357 of Keystone, get token.

Question is - how can I cut token from the responce JSON, and assign it to a variable?

Cheers,  
NM

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [October 8, 2013, 3:07pm UTC](https://forum.ansible.com/t/new-uri-module-from-romeo-theriault/12370/11 "2013-10-08T15:07:01Z")

</div>

If you run ansible-playbook with -v you will see what modules return.

You would then use the “register” statement to assign to a variable.

---

<div class="post-metadata">

**Author:** ![Nick\_Maslov](https://avatars.discourse-cdn.com/v4/letter/n/7ab992/32.png) [@Nick\_Maslov](https://forum.ansible.com/u/Nick_Maslov)\
**Post date:** [October 9, 2013, 10:01am UTC](https://forum.ansible.com/t/new-uri-module-from-romeo-theriault/12370/12 "2013-10-09T10:01:56Z")

</div>

Hi  
That`s exactly what I do now, thanks Michael.

I have a small issue, however.

- name: Test...  
&nbsp;&nbsp;shell: uname -a  
&nbsp;&nbsp;register: testvar  
&nbsp;&nbsp;tags:  
&nbsp;&nbsp;&nbsp;&nbsp;- testvar

- name: Test 1...  
&nbsp;&nbsp;shell: touch /tmp/testout  
&nbsp;&nbsp;tags:  
&nbsp;&nbsp;&nbsp;&nbsp;- testvar

- name: Test 2...  
&nbsp;&nbsp;shell: echo {{ testvar.stdout\_lines }} \> /tmp/testout  
&nbsp;&nbsp;tags:  
&nbsp;&nbsp;&nbsp;&nbsp;- testvar

# cat testout  
[uLinux ctrl01-001 3.8.0-31-generic #46-Ubuntu SMP Tue Sep 10 20:03:44 UTC 2013 x86\_64 x86\_64 x86\_64 GNU/Linux]

How can I get rid of those [u ...] braces?

Thanks,  
NM

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [October 9, 2013, 1:55pm UTC](https://forum.ansible.com/t/new-uri-module-from-romeo-theriault/12370/13 "2013-10-09T13:55:10Z")

</div>

stdout\_lines is an array, so it’s printing them as an array.

I would be more inclined to save the result to a file locally if you really wanted to do that, but I’d like to ask what the root use case actually is, as there are better ways to model this sort of thing in almost all cases than going through intermediate files.

Help me understand a bit what the real world scenario is?

---

<div class="post-metadata">

**Author:** ![Nick\_Maslov](https://avatars.discourse-cdn.com/v4/letter/n/7ab992/32.png) [@Nick\_Maslov](https://forum.ansible.com/u/Nick_Maslov)\
**Post date:** [October 10, 2013, 12:04pm UTC](https://forum.ansible.com/t/new-uri-module-from-romeo-theriault/12370/14 "2013-10-10T12:04:18Z")

</div>

Hi,

Well, usecase was rather simple - I needed to install Openstack`s Cinder with Ceph backend, and that required issuing commands that respond with hasg keys on STDOUT. Idea was to capture this output as variable and use it in consequent libvirt commands.

But I managed to route it to file and read from it.

Thanks,  
NM

---

<div class="post-metadata">

**Author:** ![bryan\_hunt1](https://avatars.discourse-cdn.com/v4/letter/b/ed8c4c/32.png) [@bryan\_hunt1](https://forum.ansible.com/u/bryan_hunt1)\
**Post date:** [March 21, 2014, 2:55pm UTC](https://forum.ansible.com/t/new-uri-module-from-romeo-theriault/12370/15 "2014-03-21T14:55:10Z")

</div>

I have this same issue when using it to create riak-cs admin users.

riak-cs will return either 201 or 409 when sending a PUT request, never a 200.

Unfortunately 201 triggers module failure, as 200 is what it expects.

riak\_cs | FAILED  
**…**  
“msg”: “Status code was not 200”,

I can work around this, but it’s going to be ugly.

---

<div class="post-metadata">

**Author:** ![bryan\_hunt1](https://avatars.discourse-cdn.com/v4/letter/b/ed8c4c/32.png) [@bryan\_hunt1](https://forum.ansible.com/u/bryan_hunt1)\
**Post date:** [March 21, 2014, 2:56pm UTC](https://forum.ansible.com/t/new-uri-module-from-romeo-theriault/12370/16 "2014-03-21T14:56:10Z")

</div>

I have this same issue when using it to create riak-cs admin users.

riak-cs will return either 201 or 409 when sending a PUT request, never a 200.

Unfortunately 201 triggers module failure, as 200 is what it expects.

riak\_cs | FAILED  
**…**  
“msg”: “Status code was not 200”,

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [March 21, 2014, 3:03pm UTC](https://forum.ansible.com/t/new-uri-module-from-romeo-theriault/12370/17 "2014-03-21T15:03:01Z")

</div>

There’s a status\_code option you can send.

[http://docs.ansible.com/uri\_module.html](http://docs.ansible.com/uri_module.html)

---

<div class="post-metadata">

**Author:** ![bryan\_hunt1](https://avatars.discourse-cdn.com/v4/letter/b/ed8c4c/32.png) [@bryan\_hunt1](https://forum.ansible.com/u/bryan_hunt1)\
**Post date:** [March 21, 2014, 4:38pm UTC](https://forum.ansible.com/t/new-uri-module-from-romeo-theriault/12370/18 "2014-03-21T16:38:46Z")

</div>

Yes, but there are two valid results, either 409 or 201.

---

<div class="post-metadata">

**Author:** ![Romeo\_Theriault](https://avatars.discourse-cdn.com/v4/letter/r/839c29/32.png) [@Romeo\_Theriault](https://forum.ansible.com/u/Romeo_Theriault)\
**Post date:** [March 21, 2014, 5:45pm UTC](https://forum.ansible.com/t/new-uri-module-from-romeo-theriault/12370/19 "2014-03-21T17:45:45Z")

</div>

You may want to check out this pull request:

[https://github.com/ansible/ansible/pull/4383/files](https://github.com/ansible/ansible/pull/4383/files)

and possibly try resubmitting it the suggested fixes. This would allow  
you to specify more than one status\_code. If you can't get to it I may  
be able to this weekend.

Romeo

---

<div class="post-metadata">

**Author:** ![bryan\_hunt1](https://avatars.discourse-cdn.com/v4/letter/b/ed8c4c/32.png) [@bryan\_hunt1](https://forum.ansible.com/u/bryan_hunt1)\
**Post date:** [March 24, 2014, 1:55pm UTC](https://forum.ansible.com/t/new-uri-module-from-romeo-theriault/12370/20 "2014-03-24T13:55:38Z")

</div>

Thanks Romeo, I have recreated a pull request.

[https://github.com/ansible/ansible/pull/6649](https://github.com/ansible/ansible/pull/6649)

[Next page](https://forum.ansible.com/t/new-uri-module-from-romeo-theriault/12370.md?page=2)
