简体   繁体   English

带有“奇数长度字符串”的 Ansible 保险库错误

[英]Ansible-vault errors with “Odd-length string”

I'm running Ansible 1.8.2 .我正在运行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?这里发生了什么以及如何解决此错误?

Turns out this error is because as of Ansible 1.8.2 it requires a very specific line-end encoding for the vaulted files.原来这个错误是因为从 Ansible 1.8.2 开始,它需要一个非常特定的行尾编码来存储文件。

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.整个问题的发生是因为我的 git 客户端正在更改换行符。 See this article for specifics: https://help.github.com/articles/dealing-with-line-endings/具体见这篇文章: https : //help.github.com/articles/dealing-with-line-endings/

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):即使使用所有这些解决方案,在我设置 EDITOR 环境变量之前,编辑 ansible Vault 文件对我不起作用(无论出于何种原因,它没有在我的 Linux 发行版上设置):

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.确定这是否适用于您的一种方法是尝试view Vault 文件(使用ansible-vault view命令),如果view工作正常但edit不起作用,那么您需要将EDITOR env 变量设置为您喜欢的编辑器。

As already linked above by @Mxx (Thx!) I have diluted the needed changes for having on LF line endings on a Windows machine:正如上面@Mxx(Thx!)已经链接的那样,我已经稀释了在Windows机器上使用LF行结尾所需的更改:

(Assuming you don't have any uncommited changes and no .gitattributes file yet) (假设您没有任何未提交的更改并且还没有 .gitattributes 文件)

# 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.我能够访问保管库而不必每次都运行 sed。

In my case I had copied the vault variable from the mobaxterm output of ansible-vault encrypt.在我的例子中,我从 ansible-vault encrypt 的 mobaxterm 输出中复制了 vault 变量。 This also included whitespace at the end.这也包括末尾的空格。 Removing the whitespace solved the problem for me.删除空格为我解决了这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM