Ansible-vault errors with "Odd-length string"
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:
$» file vaulted_vars.yml
vaulted_vars.yml: ASCII text, with CRLF line terminators
However, once I changed it to this, it started working:
$» file vaulted_vars.yml
vaulted_vars.yml: ASCII text
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/
In my case I had copied the vault variable from the mobaxterm output of ansible-vault encrypt. This also included whitespace at the end. Removing the whitespace solved the problem for me.
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):
export EDITOR="/usr/bin/vi"
One way to figure out if this applies to you is to try to view
vault files (with ansible-vault view
command) and if view
works fine but edit
doesn't, then you need to set the EDITOR env variable to your favorite editor.