4

我在尝试使用 Ansible 运行 Vagrant 时遇到问题。这是我在 Windows 7 上尝试运行vagrant upvagrant provision在终端(git bash)中遇到的错误:

ERROR! Unexpected Exception: Non-hexadecimal digit found
to see the full traceback, use -vvv
Ansible failed to complete successfully. Any error output should be
visible above. Please fix these errors and try again.

发生这种情况是因为该Ansible-vault文件.vault_pass不是十六进制的(它是一个字符串并且不能更改)。在我同事的电脑上它可以正常工作,但在我的电脑上却不行。

文件中有问题的字符串.vault_pass看起来像DBAKWeG3KOr3jKjBDbAz.

我想问题出在 Python 上,但我不确定,也不知道如何解决。

当我尝试添加-vvv这是结果:

错误!意外异常:找到非十六进制数字
完整的追溯是:

回溯(最近一次通话最后):
  文件“/usr/bin/ansible-playbook”,第 92 行,在
    exit_code = cli.run()
  运行中的文件“/usr/lib/python2.7/dist-packages/ansible/cli/playbook.py”,第 132 行
    库存=库存(装载机=装载机,variable_manager=variable_manager,host_list=self.options.inventory)
  文件“/usr/lib/python2.7/dist-packages/ansible/inventory/__init__.py”,第 85 行,在 __init__
    self.parse_inventory(host_list)
  文件“/usr/lib/python2.7/dist-packages/ansible/inventory/__init__.py”,第 144 行,在 parse_inventory
    group.vars = combine_vars(group.vars, self.get_group_variables(group.name))
  文件“/usr/lib/python2.7/dist-packages/ansible/inventory/__init__.py”,第 509 行,在 get_group_variables
    self._vars_per_group[groupname] = self._get_group_variables(groupname, vault_password=vault_password)
  _get_group_variables 中的文件“/usr/lib/python2.7/dist-packages/ansible/inventory/__init__.py”,第 527 行
    vars = combine_vars(vars, self.get_group_vars(group))
  文件“/usr/lib/python2.7/dist-packages/ansible/inventory/__init__.py”,第 707 行,在 get_group_vars
    return self._get_hostgroup_vars(host=None, group=group, new_pb_basedir=new_pb_basedir)
  _get_hostgroup_vars 中的文件“/usr/lib/python2.7/dist-packages/ansible/inventory/__init__.py”,第 746 行
    结果 = combine_vars(结果,self._variable_manager.add_group_vars_file(base_path,self._loader))
  文件“/usr/lib/python2.7/dist-packages/ansible/vars/__init__.py”,第 578 行,在 add_group_vars_file
    (名称,数据)= self._load_inventory_file(路径,加载器)
  _load_inventory_file 中的文件“/usr/lib/python2.7/dist-packages/ansible/vars/__init__.py”,第 535 行
    _found, results = self._load_inventory_file(path=p, loader=loader)
  _load_inventory_file 中的文件“/usr/lib/python2.7/dist-packages/ansible/vars/__init__.py”,第 550 行
    数据 = loader.load_from_file(路径)
  文件“/usr/lib/python2.7/dist-packages/ansible/parsing/dataloader.py”,第 113 行,在 load_from_file
    (file_data, show_content) = self._get_file_contents(file_name)
  _get_file_contents 中的文件“/usr/lib/python2.7/dist-packages/ansible/parsing/dataloader.py”,第 172 行
    数据 = self._vault.decrypt(数据)
  文件“/usr/lib/python2.7/dist-packages/ansible/parsing/vault/__init__.py”,第 169 行,解密
    b_data = this_cipher.decrypt(b_data, self.b_password)
  文件“/usr/lib/python2.7/dist-packages/ansible/parsing/vault/__init__.py”,第 674 行,解密
    数据 = unhexlify(数据)
TypeError:找到非十六进制数字
Ansible 未能成功完成。任何错误输出都应该是
上面可见。请修复这些错误,然后重试。
4

4 回答 4

6

它与加密文件末尾的 Windows 行结尾有关。只需将最后一行结尾切换到 Unix 并保存文件。

于 2017-02-28T19:38:40.483 回答
5

当编码文件包含回车 (\r) 符号时,可能会出现此问题。

如果您通过 git 获取文件,则应正确配置 git - 设置core.eol = lf.gitconfig

于 2016-06-23T22:04:48.273 回答
5

以防万一有人遇到同样的问题,我在尝试手动解密直接从 YAML 文件(或从 的输出ansible-vault encrypt_string)复制的变量时遇到了这个问题

例如:

加密字符串:

echo -n 'all that is gold does not glitter' | ansible-vault encrypt_string
Reading plaintext input from stdin. (ctrl-d to end input)
!vault |
          $ANSIBLE_VAULT;1.1;AES256
          61626566613637386434386364376236636636646263386561336463386132626335386335356463
          3930303065646433346431383463653663356332306564310a653464313035383335633065666462
          61303866343966613164623533323936383165623539623734316161373561383532326231623862
          6439306562306433360a633038626233376262373561333630356662386462343566346565636364
          64643961613064313964376266336330366566616435663130666135383739323962646563326336
          3062636437636664363039383436306535303939323535353163

尝试解密:

echo '$ANSIBLE_VAULT;1.1;AES256
          61626566613637386434386364376236636636646263386561336463386132626335386335356463
          3930303065646433346431383463653663356332306564310a653464313035383335633065666462
          61303866343966613164623533323936383165623539623734316161373561383532326231623862
          6439306562306433360a633038626233376262373561333630356662386462343566346565636364
          64643961613064313964376266336330366566616435663130666135383739323962646563326336
          3062636437636664363039383436306535303939323535353163' | ansible-vault decrypt --vault-password-file ./vault-env
[WARNING]: There was a vault format error in -: Vault format unhexlify error:
Non-hexadecimal digit found
ERROR! Vault format unhexlify error: Non-hexadecimal digit found for -

要修复它,只需删除开头的 YAML 缩进空格:

echo '$ANSIBLE_VAULT;1.1;AES256
61626566613637386434386364376236636636646263386561336463386132626335386335356463 
3930303065646433346431383463653663356332306564310a653464313035383335633065666462 
61303866343966613164623533323936383165623539623734316161373561383532326231623862 
6439306562306433360a633038626233376262373561333630356662386462343566346565636364 
64643961613064313964376266336330366566616435663130666135383739323962646563326336 
3062636437636664363039383436306535303939323535353163' | ansible-vault decrypt --vault-password-file ./vault-env 
Decryption successful
all that is gold does not glitter%
于 2020-11-19T08:42:33.010 回答
1

要添加另一个变体,这是如何发生的:拱形字符串末尾的尾随空格也会这样做:

   mysql_pw: !vault |
           $ANSIBLE_VAULT;1.1;AES256
           35336630636134383938626366353162326236363966353535356361373465616364383336366536
           6630373462316336333830643331376464633961643633380a623863373966323432646236306239
           36326465343239343766363936653631643761646562306530363262633262323966623530373664
           3239376534303565340a623262646132623033383964366438633964303633363430373463633033
           3164    < spaces here

根据偶数/奇数,您可能还会得到AnsibleVaultFormatError: Vault format unhexlify error: Odd-length string

于 2021-03-29T18:07:48.640 回答