ansible.windows.win_uri (2.3.0) — module

Interacts with webservices

Authors: Corwin Brown (@blakfeld), Dag Wieers (@dagwieers)

Install collection

Install with ansible-galaxy collection install ansible.windows:==2.3.0


Add to requirements.yml

  collections:
    - name: ansible.windows
      version: 2.3.0

Description

Interacts with FTP, HTTP and HTTPS web services.

Supports Digest, Basic and WSSE HTTP authentication mechanisms.

For non-Windows targets, use the M(ansible.builtin.uri) module instead.

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Perform a GET and Store Output
  ansible.windows.win_uri:
    url: http://example.com/endpoint
  register: http_output
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Set a HOST header to hit an internal webserver:
- name: Hit a Specific Host on the Server
  ansible.windows.win_uri:
    url: http://example.com/
    method: GET
    headers:
      host: www.somesite.com
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Perform a HEAD on an Endpoint
  ansible.windows.win_uri:
    url: http://www.example.com/
    method: HEAD
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: POST a Body to an Endpoint
  ansible.windows.win_uri:
    url: http://www.somesite.com/
    method: POST
    body: "{ 'some': 'json' }"

Inputs

    
url:
    description:
    - Supports FTP, HTTP or HTTPS URLs in the form of (ftp|http|https)://host.domain:port/path.
    required: true
    type: str

body:
    description:
    - The body of the HTTP request/response to the web service.
    type: raw

dest:
    description:
    - Output the response body to a file.
    type: path

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

headers:
    description:
    - Extra headers to set on the request.
    - This should be a dictionary where the key is the header name and the value is the
      value for that header.
    type: dict

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

proxy_url:
    description:
    - An explicit proxy to use for the request.
    - By default, the request will use the IE defined proxy unless I(use_proxy) is set
      to C(no).
    type: str

use_proxy:
    default: true
    description:
    - If C(no), it will not use the proxy defined in IE for the current user.
    type: bool

http_agent:
    default: ansible-httpget
    description:
    - Header to identify as, generally appears in web server logs.
    - This is set to the C(User-Agent) header on a HTTP request.
    type: str

url_method:
    aliases:
    - method
    default: GET
    description:
    - The HTTP Method of the request.
    type: str

client_cert:
    description:
    - The path to the client certificate (.pfx) that is used for X509 authentication.
      This path can either be the path to the C(pfx) on the filesystem or the PowerShell
      certificate path C(Cert:\CurrentUser\My\<thumbprint>).
    - The WinRM connection must be authenticated with C(CredSSP) or C(become) is used
      on the task if the certificate file is not password protected.
    - Other authentication types can set I(client_cert_password) when the cert is password
      protected.
    type: str

status_code:
    default:
    - 200
    description:
    - A valid, numeric, HTTP status code that signifies success of the request.
    - Can also be comma separated list of status codes.
    elements: int
    type: list

url_timeout:
    aliases:
    - timeout
    default: 30
    description:
    - Specifies how long the request can be pending before it times out (in seconds).
    - Set to C(0) to specify an infinite timeout.
    type: int

content_type:
    description:
    - Sets the "Content-Type" header.
    type: str

url_password:
    description:
    - The password for I(url_username).
    type: str

url_username:
    description:
    - The username to use for authentication.
    type: str

proxy_password:
    description:
    - The password for I(proxy_username).
    type: str

proxy_username:
    description:
    - The username to use for proxy 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. If the reported Content-type is "application/json", then the JSON is additionally
      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 be used on personally controlled sites using self-signed certificates.
    type: bool

follow_redirects:
    choices:
    - all
    - none
    - safe
    default: safe
    description:
    - Whether or the module should follow redirects.
    - C(all) will follow all redirect.
    - C(none) will not follow any redirect.
    - C(safe) will follow only "safe" redirects, where "safe" means that the client is
      only doing a C(GET) or C(HEAD) on the URI to which it is being redirected.
    - When following a redirected URL, the C(Authorization) header and any credentials
      set will be dropped and not redirected.
    type: str

force_basic_auth:
    default: false
    description:
    - By default the authentication header is only sent when a webservice responses 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 the original
      request.
    type: bool

maximum_redirection:
    default: 50
    description:
    - Specify how many times the module will redirect a connection to an alternative URI
      before the connection fails.
    - If set to C(0) or I(follow_redirects) is set to C(none), or C(safe) when not doing
      a C(GET) or C(HEAD) it prevents all redirection.
    type: int

client_cert_password:
    description:
    - The password for I(client_cert) if the cert is password protected.
    type: str

use_default_credential:
    default: false
    description:
    - Uses the current user's credentials when authenticating with a server protected
      with C(NTLM), C(Kerberos), or C(Negotiate) authentication.
    - Sites that use C(Basic) auth will still require explicit credentials through the
      I(url_username) and I(url_password) options.
    - The module will only have access to the user's credentials if using C(become) with
      a password, you are connecting with SSH using a password, or connecting with WinRM
      using C(CredSSP) or C(Kerberos with delegation).
    - If not using C(become) or a different auth method to the ones stated above, there
      will be no default credentials available and no authentication will occur.
    type: bool

proxy_use_default_credential:
    default: false
    description:
    - Uses the current user's credentials when authenticating with a proxy host protected
      with C(NTLM), C(Kerberos), or C(Negotiate) authentication.
    - Proxies that use C(Basic) auth will still require explicit credentials through the
      I(proxy_username) and I(proxy_password) options.
    - The module will only have access to the user's credentials if using C(become) with
      a password, you are connecting with SSH using a password, or connecting with WinRM
      using C(CredSSP) or C(Kerberos with delegation).
    - If not using C(become) or a different auth method to the ones stated above, there
      will be no default credentials available and no proxy authentication will occur.
    type: bool

Outputs

content:
  description: The raw content of the HTTP response.
  returned: success and return_content is True
  sample: '{"foo": "bar"}'
  type: str
content_length:
  description: The byte size of the response.
  returned: success
  sample: 54447
  type: int
elapsed:
  description: The number of seconds that elapsed while performing the download.
  returned: always
  sample: 23.2
  type: float
json:
  description: The json structure returned under content as a dictionary.
  returned: success and Content-Type is "application/json" or "application/javascript"
    and return_content is True
  sample:
    this-is-dependent: on the actual return content
  type: dict
status_code:
  description: The HTTP Status Code of the response.
  returned: success
  sample: 200
  type: int
status_description:
  description: A summary of the status.
  returned: success
  sample: OK
  type: str
url:
  description: The Target URL.
  returned: always
  sample: https://www.ansible.com
  type: str

See also