Ansible-vault errors with “Odd-length string”

前端 未结 4 1215
生来不讨喜
生来不讨喜 2021-01-11 18:19

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 sy

相关标签:
4条回答
  • 2021-01-11 18:57

    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.

    0 讨论(0)
  • 2021-01-11 19:06

    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)

    # 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
    

    That did the job for me. I was able to access the vault without having to run sed each time.

    0 讨论(0)
  • 2021-01-11 19:10

    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/

    0 讨论(0)
  • 2021-01-11 19:10

    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.

    0 讨论(0)
提交回复
热议问题