Added UseBasicParsing flag

win_uri uses "Invoke-WebRequest" under the covers, which apparently
uses Internet Explorer to parse a webpage. The problem is if a user
has never run Internet Explorer, it will be unable to do that. The
work around for this is to set the "-UseBasicParsing" flag.

The only advantage to having the Internet Explorer parsed page is
that you can then access the DOM as if it was a powershell
argument. That doesn't seem super useful for Ansible to be able
to do, so I set the default to be "-UseBasicParsing"
This commit is contained in:
Corwin Brown 2016-02-08 15:15:05 -06:00 committed by Matt Clay
parent 20284fed88
commit ac620b79dd
2 changed files with 62 additions and 25 deletions

View file

@ -33,6 +33,7 @@ $method = Get-AnsibleParam -obj $params "method" -default "GET"
$content_type = Get-AnsibleParam -obj $params -name "content_type" $content_type = Get-AnsibleParam -obj $params -name "content_type"
$headers = Get-AnsibleParam -obj $params -name "headers" $headers = Get-AnsibleParam -obj $params -name "headers"
$body = Get-AnsibleParam -obj $params -name "body" $body = Get-AnsibleParam -obj $params -name "body"
$use_basic_parsing = ConvertTo-Bool (Get-AnsibleParam -obj $params -name "use_basic_parsing" -default $true)
$webrequest_opts.Uri = $url $webrequest_opts.Uri = $url
Set-Attr $result.win_uri "url" $url Set-Attr $result.win_uri "url" $url
@ -43,6 +44,9 @@ Set-Attr $result.win_uri "method" $method
$webrequest_opts.ContentType = $content_type $webrequest_opts.ContentType = $content_type
Set-Attr $result.win_uri "content_type" $content_type Set-Attr $result.win_uri "content_type" $content_type
$webrequest_opts.UseBasicParsing = $use_basic_parsing
Set-Attr $result.win_uri "use_basic_parsing" $use_basic_parsing
if ($headers -ne $null) { if ($headers -ne $null) {
$req_headers = @{} $req_headers = @{}
ForEach ($header in $headers.psobject.properties) { ForEach ($header in $headers.psobject.properties) {
@ -64,4 +68,3 @@ ForEach ($prop in $response.psobject.properties) {
} }
Exit-Json $result Exit-Json $result

View file

@ -1,7 +1,7 @@
#!/usr/bin/python #!/usr/bin/python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# (c) 2015, Corwin Brown <blakfeld@gmail.com> # (c) 2015, Corwin Brown <corwin.brown@maxpoint.com>
# #
# This file is part of Ansible # This file is part of Ansible
# #
@ -24,7 +24,7 @@
DOCUMENTATION = """ DOCUMENTATION = """
--- ---
module: win_uri module: win_uri
version_added: "2.0" version_added: "2.1"
short_description: Interacts with webservices. short_description: Interacts with webservices.
description: description:
- Interacts with HTTP and HTTPS services. - Interacts with HTTP and HTTPS services.
@ -32,12 +32,10 @@ options:
url: url:
description: description:
- HTTP or HTTPS URL in the form of (http|https)://host.domain:port/path - HTTP or HTTPS URL in the form of (http|https)://host.domain:port/path
required: true
method: method:
description: description:
- The HTTP Method of the request or response. - The HTTP Method of the request or response.
default: GET default: GET
required: false
choices: choices:
- GET - GET
- POST - POST
@ -55,17 +53,20 @@ options:
body: body:
description: description:
- The body of the HTTP request/response to the web service. - The body of the HTTP request/response to the web service.
required: false
default: None
headers: headers:
description: description:
- Key Value pairs for headers. Example "Host: www.somesite.com" - Key Value pairs for headers. Example "Host: www.somesite.com"
required: false use_basic_parsing:
default: None description:
- This module relies upon 'Invoke-WebRequest', which by default uses the Internet Explorer Engine to parse a webpage. There's an edge-case where if a user hasn't run IE before, this will fail. The only advantage to using the Internet Explorer praser is that you can traverse the DOM in a powershell script. That isn't useful for Ansible, so by default we toggle 'UseBasicParsing'. However, you can toggle that off here.
choices:
- True
- False
default: True
author: Corwin Brown (@blakfeld) author: Corwin Brown (@blakfeld)
""" """
Examples = """ EXAMPLES = """
# Send a GET request and store the output: # Send a GET request and store the output:
--- ---
- name: Perform a GET and Store Output - name: Perform a GET and Store Output
@ -96,19 +97,52 @@ Examples = """
url: http://www.somesite.com url: http://www.somesite.com
method: POST method: POST
body: "{ 'some': 'json' }" body: "{ 'some': 'json' }"
"""
# Check if a file is available on a webserver
--- RETURN = """
- name: Ensure Build is Available on Fileserver url:
when: ensure_build description: The Target URL
win_uri: returned: always
url: "http://www.somesite.com" type: string
method: HEAD sample: "http://www.ansible.com"
headers: method:
test: one description: The HTTP method used.
another: two returned: always
register: build_check_output type: string
until: build_check_output.StatusCode == 200 sample: "GET"
retries: 30 content_type:
delay: 10 description: The "content-type" header used.
returned: always
type: string
sample: "application/json"
use_basic_parsing:
description: The state of the "use_basic_parsing" flag.
returned: always
type: bool
sample: True
StatusCode:
description: The HTTP Status Code of the response.
returned: success
type: int
sample: 200
StatusDescription:
description: A summery of the status.
returned: success
type: string
stample: "OK"
RawContent:
description: The raw content of the HTTP response.
returned: success
type: string
sample: 'HTTP/1.1 200 OK\nX-XSS-Protection: 1; mode=block\nX-Frame-Options: SAMEORIGIN\nAlternate-Protocol: 443:quic,p=1\nAlt-Svc: quic="www.google.com:443"; ma=2592000; v="30,29,28,27,26,25",quic=":443"; ma=2...'
Headers:
description: The Headers of the response.
returned: success
type: dict
sample: {"Content-Type": "application/json"}
RawContentLength:
description: The byte size of the response.
returned: success
type: int
sample: 54447
""" """