I'm running Ansible 1.8.2
.
I have a vaulted file created on another system. On that system it works without any 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 type in the password or copy-pasting it, but the error still happens.
What is going on here and how to fix this error?
Even with all these solutions, editing ansible vault files didn't work for me until I set the EDITOR environment variable (for whatever reason it was not set on my Linux distribution):
One way to figure out if this applies to you is to try to
view
vault files (withansible-vault view
command) and ifview
works fine butedit
doesn't, then you need to set the EDITOR env variable to your favorite editor.Some developers that use Windows, experienced the same issue. i.e. occurrence of
ERROR: Odd-length string
when runningansible
. It turned out that the files that contain the variables wereASCII text, with CRLF line terminators
:After running
sed -i 's/\r//' *_vars/*/*
thecrlf
was removed:and the ansible run succeeded.
As already linked above by @Mxx (Thx!) I have diluted the needed changes for having on LF line endings on a Windows machine:
(Assuming you don't have any uncommited changes and no .gitattributes file yet)
That did the job for me. I was able to access the vault without having to run sed each time.
Turns out this error is because as of Ansible 1.8.2 it requires a very specific line-end encoding for the vaulted files.
When I had this type of file it would fail:
However, once I changed it to this, it started working:
This whole problem happened because my git client was changing linefeed characters. See this article for specifics: https://help.github.com/articles/dealing-with-line-endings/