-
Notifications
You must be signed in to change notification settings - Fork 23.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
file lookup is not binary safe #3518
Comments
The file lookup plugin always assumes to read utf8 and removes whitespace,
|
You can of course use the src= option in this case. |
Yes, this is just a minimal example to make the bug reproducable. I noticed this when I looked into issue 3214. |
The md5sums being different, is perfectly normal due to the strip(). So the initial issue here is not really a bug to me. I couldn't reproduce any problem with
So there does seem to be a problem here. After some research I came to this Tried a patch, and this solves that ascii error. Sound like a valid fix to me, but not sure if this is a proper fix. I'll propose a PR for evaluation. |
@serge, I've used that approach with success in the past though many warn I was also thinking of adding a 'encoding' parameter to lookup to safely Brian Coca |
FWIW, I checked the variables types, only to notice that everything was and remained utf8. The problem remains in the fd's write method only. |
On Thu, Aug 08, 2013 at 01:11:57PM -0700, Serge van Ginderachter wrote:
strip() removes whitespace, therefore it is not expected that strip()
It is the character encoded in latin1. Please re-try and check whether
It suppresses the exception but is not a valid fix, unless you want |
On Thu, Aug 08, 2013 at 01:38:14PM -0700, Brian Coca wrote:
Why does ansible need to know the encoding of the file and cannot just |
You created your test file with
AFAICS it doesn't suppress the error, it somehow forces the fd.write() method to not use ASCII, but UTF8. |
On Fri, Aug 09, 2013 at 12:34:30AM -0700, Serge van Ginderachter wrote:
Ok, this explains why it is different, but now why the target file is
But if the input file is not encoded in UTF8, this is wrong. Ansible |
This fix actually breaks Ansible when it's running with redirected stdin (such as when a PlayBook is being executed in a Celery/Django task from Python code). The culprint seems to be the reload(sys) that's introduced here. It resets the redirected stdin - which messes with what the runner expects. I'm getting this fatal error:
From this very simple playbook:
It works when running ansible-playbook in the console without any redirections, so I don't know if this is considered a fringe use-case? |
@hngkr can you open a new bug please? |
Thanks for opening a new ticket. It's easy to lose comments on closed tickets since they don't show up in the open bug list. |
0xe4 is a latin1 encoded
ä
. It cannot be transfered using the FILE lookup and copy module:$ echo -e '\xe4' > ae.txt
$ ansible test -m copy --user root -a 'dest=/tmp/test content="$FILE(ae.txt)"'
test | success >> {
"changed": true,
"dest": "/tmp/test",
"gid": 0,
"group": "root",
"md5sum": "d41d8cd98f00b204e9800998ecf8427e",
"mode": "0600",
"owner": "root",
"size": 0,
"src": "/root/.ansible/tmp/ansible-1373660975.11-58729570197455/source",
"state": "file",
"uid": 0
}
$ md5sum ae.txt
6935d28700cd9056e616f514ddaf7399 ae.txt
$ md5sum /dev/null
d41d8cd98f00b204e9800998ecf8427e /dev/null
The returned md5sum of the copy modules corresponds to the empty string and not to the one of the file ae.txt
The text was updated successfully, but these errors were encountered: