Testing file upload with uri?

Hi! Anyone know if it’s possible to test the upload of a binary file using the uri module? It doesn’t look like httplib2 has this functionality . . .

Thanks,
Guy

All the arguments are passed on the command line for that module versus loaded form local files, so probably not. Patches to accept a data file to read would be accepted.

Hi! How do you feel about something like this for the uri module?

I actually don’t understand my response to the 1st question of this thread, that may have been a mis-post.

" # if body is a file URL, e.g. ‘file:///bin/false’, read it in and replace the text of body with the binary contents of the file"

Sorry, also not following.

I want to make the same (upload a release to github API with uri module).

I have seen an example posting the contents of a file:

The problem seems that lookup want to read a utf8 file:

/usr/share/pyshared/ansible/runner/lookup_plugins/file.py
ret.append(codecs.open(path, encoding=“utf8”).read().rstrip())

I was trying also something like:

  • name: read file
    shell: cat issue.rpm

register: file

  • uri: url=http://localhost
    method=POST
    HEADER_Content-Type=“application/octet-stream”

body=“{{ file.stdout }}”

But it doesn’t work:
msg: this module requires key=value arguments …

That ‘file:///’ part is there so that the uri module can be notified that the body data is actually in a file and should be read in from disk . . . I don’t really like that because it seems a little too magical.

I prefer either amending the current file lookup plugin to read binary data if the file is such (currently it is only able to read text files) or adding a bin_file lookup that is not concerned about utf8, etc.

That make any more sense? :frowning:

Thanks a lot,
Guy

Ok, yes.

The proposal seems like it should be to make the uri module take an optional “file” parameter, so the lookup plugin doesn’t have to use the content parameter.

This will prevent the need to transfer the file in the arguments, which could get ungainly for large files.

–Michael

OR - and I think I prefer this - should I create a new lookup_plugin called rawfile (binfile previously mentioned in this post) that doesn’t do any encoding and simply slurps the file in?

Should this post be in “Ansible Development”?

Thanks again,
Guy

It’s a devel topic mostly, but the answer is no, because lookup plugins are just going to evaluate to string parameters here, and this is an inefficient way to pass large files to remote hosts.

I am running into the same issues and I wonder if anyone has come up with a solution to this? +1 from me.