Interacts with HTTP and HTTPS web services and supports Digest, Basic and WSSE HTTP authentication mechanisms.
parameter | required | default | choices | comments |
---|---|---|---|---|
HEADER_ | no | Any parameter starting with "HEADER_" is a sent with your request as a header. For example, HEADER_Content-Type="application/json" would send the header "Content-Type" along with your request with a value of "application/json". This option is deprecated as of 2.1 and may be removed in a future release. Use headers instead. |
||
body | no | The body of the http request/response to the web service. If body_format is set to 'json' it will take an already formatted JSON string or convert a data structure into JSON. |
||
body_format (added in 2.0)
| no | raw |
| The serialization format of the body. When set to json, encodes the body argument, if needed, and automatically sets the Content-Type header accordingly. |
creates | no | a filename, when it already exists, this step will not be run. |
||
dest | no | path of where to download the file to (if desired). If dest is a directory, the basename of the file on the remote server will be used. |
||
follow_redirects | no | safe |
| Whether or not the URI module should follow redirects. all will follow all redirects. safe will follow only "safe" redirects, where "safe" means that the client is only doing a GET or HEAD on the URI to which it is being redirected. none will not follow any redirects. Note that yes and no choices are accepted for backwards compatibility, where yes is the equivalent of all and no is the equivalent of safe . yes and no are deprecated and will be removed in some future version of Ansible. |
force_basic_auth | no | no |
| The library used by the uri module only sends authentication information when a webservice responds to an initial request with a 401 status. Since some basic auth services do not properly send a 401, logins will fail. This option forces the sending of the Basic authentication header upon initial request. |
headers (added in 2.1)
| no | Add custom HTTP headers to a request in the format of a YAML hash |
||
method | no | GET |
| The HTTP method of the request or response. It MUST be uppercase. |
others | no | all arguments accepted by the file module also work here |
||
password | no | password for the module to use for Digest, Basic or WSSE authentication. |
||
removes | no | a filename, when it does not exist, this step will not be run. |
||
return_content | no | no |
| Whether or not to return the body of the request as a "content" key in the dictionary result. If the reported Content-type is "application/json", then the JSON is additionally loaded into a key called json in the dictionary results. |
status_code | no | 200 | A valid, numeric, HTTP status code that signifies success of the request. Can also be comma separated list of status codes. |
|
timeout | no | 30 | The socket level timeout in seconds |
|
url | yes | HTTP or HTTPS URL in the form (http|https)://host.domain[:port]/path |
||
user | no | username for the module to use for Digest, Basic or WSSE authentication. |
||
validate_certs (added in 1.9.2)
| no | yes |
| If no , SSL certificates will not be validated. This should only set to no used on personally controlled sites using self-signed certificates. Prior to 1.9.2 the code defaulted to no . |
# Check that you can connect (GET) to a page and it returns a status 200 - uri: url=http://www.example.com # Check that a page returns a status 200 and fail if the word AWESOME is not # in the page contents. - action: uri url=http://www.example.com return_content=yes register: webpage - action: fail when: "'AWESOME' not in webpage.content" # Create a JIRA issue - uri: url: https://your.jira.example.com/rest/api/2/issue/ method: POST user: your_username password: your_pass body: "{{ lookup('file','issue.json') }}" force_basic_auth: yes status_code: 201 body_format: json # Login to a form based webpage, then use the returned cookie to # access the app in later tasks - uri: url: https://your.form.based.auth.example.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 - uri: url: https://your.form.based.auth.example.com/dashboard.php method: GET return_content: yes HEADER_Cookie: "{{login.set_cookie}}" # Queue build of a project in Jenkins: - uri: url: "http://{{ jenkins.host }}/job/{{ jenkins.job }}/build?token={{ jenkins.token }}" method: GET user: "{{ jenkins.user }}" password: "{{ jenkins.password }}" force_basic_auth: yes status_code: 201
Note
The dependency on httplib2 was removed in Ansible 2.1
For more information on what this means please read Core Modules
For help in developing on modules, should you be so inclined, please read Community Information & Contributing, developing_test_pr and Developing Modules.
© 2012–2016 Michael DeHaan
© 2016 Red Hat, Inc.
Licensed under the GNU General Public License version 3.
https://docs.ansible.com/ansible/uri_module.html