使用加密的group_vars运行剧本时出错

时间:2019-05-26 20:44:16

标签: ansible ansible-2.x

我正在尝试使用包含使用ansible-vault加密的文件的剧本。但是,出现以下错误:

ERROR! Syntax Error while loading YAML.
  could not find expected ':'

The error appears to have been in 'inventories/group_vars/main_server': line 41, column 1, but may
be elsewhere in the file depending on the exact syntax problem.

库文件的内容:

me@server:ansible$ cat inventories/group_vars/main_server
$ANSIBLE_VAULT;1.1;AES256
...

我正在运行的命令:

ansible-playbook -i inventories/group_vars/main_server --extra-vars "target=my_target" playbook.yml --ask-become-pass --ask-pass --vault-password-file vault_pwd.txt

vault_pwd.txt填充了所需的密码。在开发剧本时,我一直在进行加密/解密。例如,带有加密命令的shell脚本:

ansible-vault encrypt inventories/group_vars/main_server --vault-password-file vault_pwd.txt

编辑#1

Ansible版本:

me@server:ansible$ ansible --version
ansible 2.7.5
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/me/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/dist-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.12 (default, Nov 12 2018, 14:36:49) [GCC 5.4.0 20160609]

1 个答案:

答案 0 :(得分:1)

您看到的错误...

  

错误!加载YAML时的语法错误。     找不到预期的':'

     

错误似乎出在'inventories / group_vars / main_server'中:第41行第1列,但可能   根据确切的语法问题放在文件的其他位置。

...是YAML语法错误。 Ansible可能会抱怨未加密内容中的实际语法错误(并且如果您很幸运,错误消息中引用的行实际上就是出现错误的行)。