diff --git a/lib/ansible/modules/extras/windows/win_uri.ps1 b/lib/ansible/modules/extras/windows/win_uri.ps1 index 9c2ddededae..cb4fda226ef 100644 --- a/lib/ansible/modules/extras/windows/win_uri.ps1 +++ b/lib/ansible/modules/extras/windows/win_uri.ps1 @@ -1,7 +1,7 @@ #!powershell # This file is part of Ansible # -# Copyright 2015, Corwin Brown +# Copyright 2015, Corwin Brown # # Ansible is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -27,32 +27,22 @@ $result = New-Object psobject @{ # Build Arguments $webrequest_opts = @{} -if (Get-Member -InputObject $params -Name url) { - $url = $params.url.ToString() - $webrequest_opts.Uri = $url -} else { - Fail-Json $result "Missing required argument: url" -} -if (Get-Member -InputObject $params -Name method) { - $method = $params.method.ToString() - $webrequest_opts.Method = $method -} +$url = Get-AnsibleParam -obj $params -name "url" -failifempty $true +$method = Get-AnsibleParam -obj $params "method" -default "GET" +$content_type = Get-AnsibleParam -obj $params -name "content_type" +$body = Get-AnsibleParam -obj $params -name "body" -if (Get-Member -InputObject $params -Name content_type) { - $content_type = $params.method.content_type.ToString() - $webrequest_opts.ContentType = $content_type -} +$webrequest_opts.Uri = $url +Set-Attr $result.win_uri "url" $url -if (Get-Member -InputObject $params -Name body) { - $body = $params.method.body.ToString() - $webrequest_opts.Body = $body -} +@webrequest_opts.Method = $method +Set-Attr $result.win_uri "method" $method -if (Get-Member -InputObject $params -Name headers) { - $headers = $params.headers - Set-Attr $result.win_uri "headers" $headers +@webrequest_opts.content_type = $content_type +Set-Attr $result.content_type "content_type" $content_type +if ($headers -ne $null) { $req_headers = @{} ForEach ($header in $headers.psobject.properties) { $req_headers.Add($header.Name, $header.Value) diff --git a/lib/ansible/modules/extras/windows/win_uri.py b/lib/ansible/modules/extras/windows/win_uri.py index 451c965836d..161533631f9 100644 --- a/lib/ansible/modules/extras/windows/win_uri.py +++ b/lib/ansible/modules/extras/windows/win_uri.py @@ -24,7 +24,7 @@ DOCUMENTATION = """ --- module: win_uri -version_added: "" +version_added: "2.0" short_description: Interacts with webservices. description: - Interacts with HTTP and HTTPS services. @@ -32,10 +32,12 @@ options: url: description: - HTTP or HTTPS URL in the form of (http|https)://host.domain:port/path + required: true method: description: - The HTTP Method of the request or response. default: GET + required: false choices: - GET - POST @@ -53,13 +55,17 @@ options: body: description: - The body of the HTTP request/response to the web service. + required: false + default: None headers: description: - Key Value pairs for headers. Example "Host: www.somesite.com" -author: Corwin Brown + required: false + default: None +author: Corwin Brown (@blakfeld) """ -Examples= """ +Examples = """ # Send a GET request and store the output: --- - name: Perform a GET and Store Output @@ -90,4 +96,19 @@ Examples= """ url: http://www.somesite.com method: POST body: "{ 'some': 'json' }" + +# Check if a file is available on a webserver +--- +- name: Ensure Build is Available on Fileserver + when: ensure_build + win_uri: + url: "http://www.somesite.com" + method: HEAD + headers: + test: one + another: two + register: build_check_output + until: build_check_output.StatusCode == 200 + retries: 30 + delay: 10 """