ansible / ansible-modules-extras

Ansible extra modules - these modules ship with ansible
947 stars 1.47k forks source link

win_uri : PUT method - payload size = 0 #2999

Closed manpw closed 7 years ago

manpw commented 8 years ago

hi,

I am using win_uri to put an archive under artifactory.

ISSUE TYPE

win_uri

ANSIBLE VERSION

ansible 2.1.0.0 (detached HEAD b599477242) last updated 2016/09/20 16:05:45 (GMT +200) lib/ansible/modules/core: (detached HEAD 04a871d007) last updated 2016/09/20 16:05:48 (GMT +200) lib/ansible/modules/extras: (detached HEAD b5fa2b3416) last updated 2016/09/20 16:05:50 (GMT +200)


##### CONFIGURATION
défault config

##### OS / ENVIRONMENT
Windows 7 PRO 2009 Service Pack 1

##### SUMMARY
win_uri  module do upload but content file is nul

##### STEPS TO REPRODUCE

name: PUT Generated BI Archive To Artifactory win_uri: url: '{{ test_url}}/{{ version}}/{{ artifactId}}.zip' method: PUT body: "{ '{{ deployDir }}Test_Export_UL.zip': 'application/zip' }" content_type: "application/zip" headers: Authorization: Basic {{ bi_user_pwd | b64encode }} register: stat_repo_upload


##### EXPECTED RESULTS
upload a archive file in artifactory
uploaded archive file must have content (originale size)

##### ACTUAL RESULTS
a zip file is uploaded without content : size=0 ko
log below :  
ok: [IP-MACHINE] => {"base_response": {"CharacterSet": "ISO-8859-1", "ContentEncoding": "", "ContentLength": -1, 
"ContentType": "application/vnd.org.jfrog.artifactory.storage.ItemCreated+json;charset=ISO-8859-1", "Cookies": [], 
"Headers": ["Transfer-Encoding", "Proxy-Connection", "Connection", "Age", "Cache-Control", "Content-Type", "Date", "Location", "Server"], 
"IsFromCache": false, "IsMutuallyAuthenticated": false, "LastModified": "/Date(1474475509586)/", "Method": "PUT", 
"ProtocolVersion": {"Build": -1, "Major": 1, "MajorRevision": -1, "Minor": 1, "MinorRevision": -1, "Revision": -1}, 
"ResponseUri": "http://artifactory-server/simple/libs-releases-local/com/manpower/bi/cognos/Test_UL/2.0.10/Test_Export_UL.zip", 
"Server": "Artifactory/2.6.1", "StatusCode": 201, "StatusDescription": "Created", "SupportsHeaders": true}, 
"changed": false, "content": [123, 10, 32, 32, 34, 114, 101, 112, 11, 34, 32, 58, 32, 34, 108, 105, 98, 115, 45, 114, 101, 108, 101, 97, 115, 101, 115, 45, 108, 111, 99, 97, 108, 34, 44, 10, 32, 32, 34, 112, 97, 116, 104, 34, 32, 58, 32, 34, 47, 99, 111, 109, 47, 109, 97, 110, 112, 111, 119, 101, 114, 47, 98, 105, 47, 99, 111, 103, 110, 111, 115, 47, 84, 101, 115, 116, 95, 85, 76, 47, 50, 46, 48, 46, 49, 48, 47, 84, 101, 115, 116, 95, 69, 120, 112, 111, 114, 116, 95, 85, 76, 46, 122, 105, 112, 34, 44, 10, 32, 32, 34, 99, 114, 101, 97, 116, 101, 100, 34, 32, 58, 32, 34, 50, 48, 49, 54, 45, 48, 57, 45, 50, 49, 84, 49, 56, 58, 51, 49, 58, 52, 57, 46, 48, 52, 56, 43, 48, 50, 58, 48, 48, 34, 44, 10, 32, 32, 34, 99, 114, 101, 97, 116, 101, 100, 66, 121, 34, 32, 58, 32, 34, 98, 105, 45, 99, 111, 103, 110, 111, 115, 34, 44, 10, 32, 32, 34, 100, 111, 119, 110, 108, 111, 97, 100, 85, 114, 105, 34, 32, 58, 32, 34, 104, 116, 116, 112, 58, 47, 47, 100, 101, 112, 111, 116, 46, 109, 112, 119, 46, 102, 114, 97, 47, 108, 105, 98, 115, 45, 114, 101, 108, 101, 97, 115, 101, 115, 45, 108, 111, 99, 97, 108, 47, 99, 111, 109, 47, 109, 97, 110, 112, 111, 119, 101, 114, 47, 98, 105, 47, 99, 111, 103, 110, 111, 115, 47, 84, 101, 115, 116, 95, 85, 76, 47, 50, 46, 48, 46, 49, 48, 47, 84, 101, 115, 116, 95, 69, 120, 112, 111, 114, 116, 95, 85, 76, 46, 122, 105, 112, 34, 44, 10, 32, 32, 34, 109, 105, 109, 101, 84, 121, 112, 101, 34, 32, 58, 32, 34, 97, 112, 112, 108, 105, 99, 97, 116, 105, 111, 110, 47, 122, 105, 112, 34, 44, 10, 32, 32, 34, 115, 105, 122, 101, 34, 32, 58, 32, 48, 44, 10, 32, 32, 34, 99, 104, 101, 99, 107, 115, 117, 109, 115, 34, 32, 58, 32, 123, 10, 32, 32, 32, 32, 34, 115, 104, 97, 49, 34, 32, 58, 32, 34, 100, 97, 51, 57, 97, 51, 101, 101, 53, 101, 54, 98, 52, 98, 48, 100, 51, 50, 53, 53, 98, 102, 101, 102, 57, 53, 54, 48, 49, 56, 57, 48, 97, 102, 100, 56, 48, 55, 48, 57, 34, 44, 10, 32, 32, 32, 32, 34, 109, 100, 53, 34, 32, 58, 32, 34, 100, 52, 49, 100, 56, 99, 100, 57, 56, 102, 48, 48, 98, 50, 48, 52, 101, 57, 56, 48, 48, 57, 57, 56, 101, 99, 102, 56, 52, 50, 55, 101, 34, 10, 32, 32, 125, 44, 10, 32, 32, 34, 111, 114, 105, 103, 105, 110, 97, 108, 67, 104, 101, 99, 107, 115, 117, 109, 115, 34, 32, 58, 32, 123, 10, 32, 32, 125, 44, 10, 32, 32, 34, 117, 114, 105, 34, 32, 58, 32, 34, 104, 116, 116, 112, 58, 47, 47, 100, 101, 112, 111, 116, 46, 109, 112, 119, 46, 102, 114, 97, 47, 108, 105, 98, 115, 45, 114, 101, 108, 101, 97, 115, 101, 115, 45, 108, 111, 99, 97, 108, 47, 99, 111, 109, 47, 109, 97, 110, 112, 111, 119, 101, 114, 47, 98, 105, 47, 99, 111, 103, 110, 111, 115, 47, 84, 101, 115, 116, 95, 85, 76, 47, 50, 46, 48, 46, 49, 48, 47, 84, 101, 115, 116, 95, 69, 120, 112, 111, 114, 116, 95, 85, 76, 46, 122, 105, 112, 34, 10, 125], "headers": {"Age": "0", "Cache-Control": "proxy-revalidate", "Connection": "Keep-Alive", "Content-Type": "application/vnd.org.jfrog.artifactory.storage.ItemCreated+json;charset=ISO-8859-1", "Date": "Wed, 21 Sep 2016 16:31:49 GMT", "Location": "http://artifactory-server/libs-releases-local/com/manpower/bi/cognos/Test_UL/2.0.10/Test_Export_UL.zip", "Proxy-Connection": "Keep-Alive", "Server": "Artifactory/2.6.1", "Transfer-Encoding": "chunked"}, "raw_content": "HTTP/1.1 201 Created\r\nTransfer-Encoding: chunked\r\nProxy-Connection: Keep-Alive\r\nConnection: Keep-Alive\r\nAge: 0\r\nCache-Control: proxy-revalidate\r\nContent-Type: application/vnd.org.jfrog.artifactory.storage.ItemCreated+json;charset=ISO-8859-1\r\nDate: Wed, 21 Sep 2016 16:31:49 GMT\r\nLocation: http://artifactory-server/libs-releases-local/com/manpower/bi/cognos/Test_UL/2.0.10/Test_Export_UL.zip
\r\nServer: Artifactory/2.6.1\r\n\r\n{\n  \"repo\" : \"libs-releases-local\",\n  
\"path\" : \"/com/manpower/bi/cognos/Test_UL/2.0.10/Test_Export_UL.zip\",\n  \"created\" : \"2016-09-21T18:31:49.048+02:00\",
\n  \"createdBy\" : \"myuser\",
\n  \"downloadUri\" : \"http://artifactory-server/libs-releases-local/com/manpower/bi/cognos/Test_UL/2.0.10/Test_Export_UL.zip\",
\n  \"mimeType\" : \"application/zip\",\n  \"size\" : 0,
\n  \"checksums\" : {\n    \"sha1\" : \"da39a3ee5e6b4b0d3255bfef95601890afd80709\",\n    \"md5\" : \"d41d8cd98f00b204e9800998ecf8427e\"\n  },\n  \"originalChecksums\" : {\n  },
\n  \"uri\" : \"http://artifactory-server/libs-releases-local/com/manpower/bi/cognos/Test_UL/2.0.10/Test_Export_UL.zip\"\n}", 
"raw_content_length": 620, 
"raw_content_stream": {"CanRead": true, "CanSeek": true, "CanTimeout": false, "CanWrite": true, "Capacity": 100000, "Length": 620, "Position": 620, "ReadTimeout": null, "WriteTimeout": null}, 
"status_code": 201, "status_description": "Created", 
"win_uri": {"content_type": "application/zip", "method": "PUT", 
"url": "http://artifactory-server/simple/libs-releases-local/com/manpower/bi/cognos/Test_UL/2.0.10/Test_Export_UL.zip", "use_basic_parsing": true}}
ansibot commented 8 years ago

@blakfeld ping, this issue is waiting for your response. click here for bot help

blakfeld commented 8 years ago

I'm 99% sure that this has to do with "body" not actually grabbing the file. It looks like with Powershell you'd have to have the 'InFile' flag (at least that's what is noted here: https://www.jfrog.com/knowledge-base/how-do-i-execute-a-file-upload-via-powershell/)

The answer here might be to have a "file" key? I'm not sure what the best user interface is for that.

I'll try and jump on this as soon as I can, but I don't have a lot of access to windows boxes to test this on anymore. If someone wants to take it, the answer is adding the '-InFile' flag to the Invoke-Webrequest bit.

blakfeld commented 8 years ago

So I think I have some code to fix this, but I've moved to an all Linux shop, so my testing vectors are limited. When I submit a pull request, would you able to see if it fixes your problem?

blakfeld commented 8 years ago

When you get a chance, can you test this code? It seems to work for me, but I'd love confirmation before I merge it.

ansibot commented 7 years ago

@blakfeld, ping. This issue is still waiting on your response. click here for bot help

ansibot commented 7 years ago

@blakfeld, ping. This issue is still waiting on your response. click here for bot help

ansibot commented 7 years ago

@blakfeld, ping. This issue is still waiting on your response. click here for bot help

blakfeld commented 7 years ago

I have a PR ready for this, but for some reason the build is failing.

ansibot commented 7 years ago

@blakfeld, ping. This issue is still waiting on your response. click here for bot help

ansibot commented 7 years ago

This repository has been locked. All new issues and pull requests should be filed in https://github.com/ansible/ansible

Please read through the repomerge page in the dev guide. The guide contains links to tools which automatically move your issue or pull request to the ansible/ansible repo.

jcgarrido commented 7 years ago

The same issue is happening in Ansible 2.2.1 and specifying the body directly in the task instead of reading from a file:

    - name: Set server as TPS Processor
      win_uri:
        url: "http://{{ groups['tps'][0] }}:8080/WSGeomanager/DirectoryService/registerProcessServer"
        method: POST
        content_type: 'application/xml'
        body: "<ProcessServer>
              <id>-1</id>
              <name></name>
              <displayName>{{ inventory_hostname }}</displayName>
              <host>{{ inventory_hostname }}</host>
              <port>8080</port>
              <processors>1</processors>
              <executingProcessors>
                <value>0</value>
              </executingProcessors>
              <control>
                <id>-1</id>
                <appContext>/WSGeomanager</appContext>
                <host>{{ groups['tps'][0] }}</host>
                <port>8080</port>
              </control>
              <priority>1</priority>
              </ProcessServer>"

A network trace shows that the payload is empty:

win_uri

blakfeld commented 7 years ago

I had a fix for this, but I think it got lost when they merged the repos. I've got some free time this week, let me see what I can cook up. Are you up for testing a PR later on?

jcgarrido commented 7 years ago

Sure, I'll be glad to test it.

blakfeld commented 7 years ago

@jcgarrido Try this out: https://github.com/blakfeld/ansible/blob/add_body_file_win_uri/lib/ansible/modules/windows/win_uri.ps1

I haven't seen anything compelling as to why it's not at least attempting to POST the xml as a string blob, but when googling around it seems that everyone using XML seems to recommend using a file. I know this may not be ideal, but does this at least get you unblocked?

Really, I think the actual answer is reworking the body param to accept a dict, as opposed to just some string. Then I believe Invoke-Webrequest will just figure out how to properly format the data.

The problem is I'm generally a Linux admin, and I don't currently have access to the Windows fleet I wrote this module for, so if you have suggestions on improving it, I'll happily accept a PR.

jcgarrido commented 7 years ago

@blakfeld It turned out that I was using quite and old version of the module bundled with Ansible 2.2.0:

https://github.com/ansible/ansible-modules-extras/blob/f564e77a0848824874f111bad44f427537dddc30/windows/win_uri.ps1

I have found that in that version $body is set but never used.

More recent versions of the file already include a fix for that, it was fixed here: https://github.com/ansible/ansible-modules-extras/pull/2504

Thanks a lot for your support.

jhawkesworth commented 7 years ago

Since the issue appears to have been fixed in #2504, which would have been released in ansible 2.3.0, I am going to close this. If there are still related issues with this, please open a new issue (in https://github.com/ansible/ansible as ansible-modules-extra is no longer being used for issue tracking or pull requests.