Errors with unrelated storage with the string "Odd length"

I am running Ansible 1.8.2 . I have a vault file created on another system. On this system, it works without problems. However, when I run it on my local system, I get the following error:

 $ยป ansible-vault --debug view vars/vaulted_vars.yml Vault password: Traceback (most recent call last): File "/usr/bin/ansible-vault", line 225, in main fn(args, options, parser) File "/usr/bin/ansible-vault", line 172, in execute_view this_editor.view_file() File "/usr/lib/python2.7/site-packages/ansible/utils/vault.py", line 280, in view_file dec_data = this_vault.decrypt(tmpdata) File "/usr/lib/python2.7/site-packages/ansible/utils/vault.py", line 136, in decrypt data = this_cipher.decrypt(data, self.password) File "/usr/lib/python2.7/site-packages/ansible/utils/vault.py", line 545, in decrypt data = unhexlify(data) TypeError: Odd-length string ERROR: Odd-length string 

I tried to manually enter the password or copy it, but the error still occurs.

What is going on here and how to fix this error?

+8
ansible
source share
4 answers

It turns out that this error is due to the fact that Ansible 1.8.2 requires a very specific end-of-line encoding for summary files.

When I had this type of file, it will fail:

 $ยป file vaulted_vars.yml vaulted_vars.yml: ASCII text, with CRLF line terminators 

However, as soon as I changed it to this, it started working:

 $ยป file vaulted_vars.yml vaulted_vars.yml: ASCII text 

All this problem arose because my git client was changing the line feed characters. See this article for specifics: https://help.github.com/articles/dealing-with-line-endings/

+14
source share

Even with all these solutions, editing files with saved repositories did not work for me until I set the EDITOR environment variable (for some reason it was not set in my Linux distribution):

 export EDITOR="/usr/bin/vi" 

One way to find out if this applies to you is to try to execute the view files of the repository (using the ansible-vault view command), and if view works fine and edit doesn't, then you need to set EDITOR env to your favorite editor.

+1
source share

Some developers who use Windows have faced the same problem. those. the appearance of ERROR: Odd-length string when running ansible . It turned out that the files containing the variables were ASCII text, with CRLF line terminators :

 user@host ~/path/to/ansible $ file *_vars/*/* group_vars/groupname/vars: ASCII text, with CRLF line terminators host_vars/hostname/vars: ASCII text, with CRLF line terminators 

After running sed -i 's/\r//' *_vars/*/* crlf was removed:

 user@host ~/path/to/ansible $ file *_vars/*/* group_vars/groupname/vars: ASCII text host_vars/hostname/vars: ASCII text 

and successful run.

0
source share

As @Mxx mentioned above (thanks!), I have laid out the necessary changes so that at the ends of the LF lines on the Windows machine:

(Assuming you have no unmanaged changes and no .gitattributes file)

 # create the .gitattributes file to set the line endings only for this repo C:\projects\lfonly>copy con .gitattributes * text eol=lf ^Z (thats F6 + Enter) 1 file(s) copied. # delete all cached local file! Warning any uncommited changes will be lost git rm --cached -r . git reset --hard 

It helps me. I was able to access the repository without having to run sed every time.

0
source share

All Articles