0
votes

I am trying to run a playbook with a file that has been encrypted using ansible-vault. However, I get the following error:

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.

Content of vault file:

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

Command I'm running:

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 is populated with the required password. I have been encrypting/decrypting as I develop my playbook. For instance, the shell script with the encrypting command:

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

Edit #1

Version of 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
It is likely that the error stems from a YAML syntax issue in the vaulted content. You will need to show us the un-encrypted content of the vaulted file in order to debug this problem.larsks
Thanks for this! I'll have a look t here. I hadn't considered this.TekiusFanatikus
I used "=" to assign a value in one spot instead of a colon. The other was an IP that was missing double quotes. If you specify an answer, I will accept it.TekiusFanatikus
Please confirm: you're providing the inventory file VAULTED (encrypted)? It looks like that specific use case isn't supported: github.com/ansible/ansible/issues/10408dan_linder
Glad to help. There you go!larsks

1 Answers

1
votes

The error you're seeing...

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.

...is a YAML syntax error. Ansible is probably complaining about an actual syntax error in the unencrypted content (and if you're lucky, the line referenced in the error message is in fact the one with the error).