nsocwx.custom_modules.duo_uri (1.3.0) — module

Interacts with webservices

| "added in version" 1.1 of nsocwx.custom_modules"

Authors: Romeo Theriault (@romeotheriault)

stableinterface | supported by core

Install collection

Install with ansible-galaxy collection install nsocwx.custom_modules:==1.3.0


Add to requirements.yml

  collections:
    - name: nsocwx.custom_modules
      version: 1.3.0

Description

Interacts with HTTP and HTTPS web services and supports Digest, Basic and WSSE HTTP authentication mechanisms.

For Windows targets, use the M(win_uri) module instead.

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Check that you can connect (GET) to a page and it returns a status 200
  uri:
    url: http://www.example.com
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Check that a page returns a status 200 and fail if the word AWESOME is not in the page contents
  uri:
    url: http://www.example.com
    return_content: yes
  register: this
  failed_when: "'AWESOME' not in this.content"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Create a JIRA issue
  uri:
    url: https://your.jira.example.com/rest/api/2/issue/
    user: your_username
    password: your_pass
    method: POST
    body: "{{ lookup('file','issue.json') }}"
    force_basic_auth: yes
    status_code: 201
    body_format: json
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: 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_format: form-urlencoded
    body:
      name: your_username
      password: your_password
      enter: Sign in
    status_code: 302
  register: login
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Login to a form based webpage using a list of tuples
  uri:
    url: https://your.form.based.auth.example.com/index.php
    method: POST
    body_format: form-urlencoded
    body:
    - [ name, your_username ]
    - [ password, your_password ]
    - [ enter, Sign in ]
    status_code: 302
  register: login
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Connect to website using a previously stored cookie
  uri:
    url: https://your.form.based.auth.example.com/dashboard.php
    method: GET
    return_content: yes
    headers:
      Cookie: "{{ login.set_cookie }}"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Queue build of a project in Jenkins
  uri:
    url: http://{{ jenkins.host }}/job/{{ jenkins.job }}/build?token={{ jenkins.token }}
    user: "{{ jenkins.user }}"
    password: "{{ jenkins.password }}"
    method: GET
    force_basic_auth: yes
    status_code: 201
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: POST from contents of local file
  uri:
    url: https://httpbin.org/post
    method: POST
    src: file.json
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: POST from contents of remote file
  uri:
    url: https://httpbin.org/post
    method: POST
    src: /path/to/my/file.json
    remote_src: yes

Inputs

    
src:
    description:
    - Path to file to be submitted to the remote server.
    - Cannot be used with I(body).
    type: path
    version_added: '2.7'
    version_added_collection: nsocwx.custom_modules

url:
    description:
    - HTTP or HTTPS URL in the form (http|https)://host.domain[:port]/path
    required: true
    type: str

body:
    description:
    - The body of the http request/response to the web service. If C(body_format) is set
      to 'json' it will take an already formatted JSON string or convert a data structure
      into JSON. If C(body_format) is set to 'form-urlencoded' it will convert a dictionary
      or list of tuples into an 'application/x-www-form-urlencoded' string. (Added in
      v2.7)
    type: raw

dest:
    description:
    - A path of where to download the file to (if desired). If I(dest) is a directory,
      the basename of the file on the remote server will be used.
    type: path

force:
    aliases:
    - thirsty
    default: false
    description:
    - If C(yes) do not get a cached copy.
    type: bool

method:
    default: GET
    description:
    - The HTTP method of the request or response.
    - In more recent versions we do not restrict the method at the module level anymore
      but it still must be a valid method accepted by the service handling the request.
    type: str

others:
    description:
    - All arguments accepted by the M(file) module also work here

creates:
    description:
    - A filename, when it already exists, this step will not be run.
    type: path

headers:
    description:
    - Custom headers will be auto generated using the Duo sign function
    type: dict
    version_added: '2.1'
    version_added_collection: nsocwx.custom_modules

removes:
    description:
    - A filename, when it does not exist, this step will not be run.
    type: path

timeout:
    default: 30
    description:
    - The socket level timeout in seconds
    type: int

use_proxy:
    default: true
    description:
    - If C(no), it will not use a proxy, even if one is defined in an environment variable
      on the target hosts.
    type: bool

client_key:
    description:
    - PEM formatted file that contains your private key to be used for SSL client authentication.
    - If I(client_cert) contains both the certificate and key, this option is not required.
    type: path
    version_added: '2.4'
    version_added_collection: nsocwx.custom_modules

http_agent:
    default: ansible-httpget
    description:
    - Header to identify as, generally appears in web server logs.
    type: str

remote_src:
    default: false
    description:
    - If C(no), the module will search for src on originating/master machine.
    - If C(yes) the module will use the C(src) path on the remote/target machine.
    type: bool
    version_added: '2.7'
    version_added_collection: nsocwx.custom_modules

body_format:
    choices:
    - form-urlencoded
    - json
    - raw
    default: raw
    description:
    - The serialization format of the body. When set to C(json) or C(form-urlencoded),
      encodes the body argument, if needed, and automatically sets the Content-Type header
      accordingly. As of C(2.3) it is possible to override the `Content-Type` header,
      when set to C(json) or C(form-urlencoded) via the I(headers) option.
    type: str
    version_added: '2.0'
    version_added_collection: nsocwx.custom_modules

client_cert:
    description:
    - PEM formatted certificate chain file to be used for SSL client authentication.
    - This file can also include the key as well, and if the key is included, I(client_key)
      is not required
    type: path
    version_added: '2.4'
    version_added_collection: nsocwx.custom_modules

status_code:
    default:
    - 200
    description:
    - A list of valid, numeric, HTTP status codes that signifies success of the request.
    type: list

unix_socket:
    description:
    - Path to Unix domain socket to use for connection
    version_added: '2.8'
    version_added_collection: nsocwx.custom_modules

url_password:
    aliases:
    - password
    description:
    - A password for the module to use for Digest, Basic or WSSE authentication.
    type: str

url_username:
    aliases:
    - user
    description:
    - A username for the module to use for Digest, Basic or WSSE authentication.
    type: str

return_content:
    default: false
    description:
    - Whether or not to return the body of the response as a "content" key in the dictionary
      result.
    - Independently of this option, if the reported Content-type is "application/json",
      then the JSON is always loaded into a key called C(json) in the dictionary results.
    type: bool

validate_certs:
    default: true
    description:
    - If C(no), SSL certificates will not be validated.
    - This should only set to C(no) used on personally controlled sites using self-signed
      certificates.
    - Prior to 1.9.2 the code defaulted to C(no).
    type: bool
    version_added: 1.9.2
    version_added_collection: nsocwx.custom_modules

follow_redirects:
    choices:
    - all
    - none
    - safe
    default: safe
    description:
    - Whether or not the URI module should follow redirects. C(all) will follow all redirects.
      C(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. C(none) will
      not follow any redirects. Note that C(yes) and C(no) choices are accepted for backwards
      compatibility, where C(yes) is the equivalent of C(all) and C(no) is the equivalent
      of C(safe). C(yes) and C(no) are deprecated and will be removed in some future version
      of Ansible.
    type: str

force_basic_auth:
    default: false
    description:
    - Force the sending of the Basic authentication header upon initial request.
    - 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.
    type: bool

Outputs

elapsed:
  description: The number of seconds that elapsed while performing the download
  returned: on success
  sample: 23
  type: int
msg:
  description: The HTTP message from the request
  returned: always
  sample: OK (unknown bytes)
  type: str
redirected:
  description: Whether the request was redirected
  returned: on success
  sample: false
  type: bool
status:
  description: The HTTP status code from the request
  returned: always
  sample: 200
  type: int
url:
  description: The actual URL used for the request
  returned: always
  sample: https://www.ansible.com/
  type: str

See also