読者です 読者をやめる 読者になる 読者になる

playbook の値にコロンを入れると「ERROR! Syntax Error while loading YAML.」「We could be wrong, but this one looks like it might be an issue with unbalanced quotes. If starting a value with a quote, make sure the line ends with the same set of quotes.」

ansible

問題

Ansible の playbook 内の lineinfile の値にコロンが入っていると Syntax error になる。

  • playbook の該当箇所
 - lineinfile: dest="/etc/elasticsearch/elasticsearch.yml" regexp="# network.ost" line='network.host: 0.0.0.0'
  • エラーメッセージ
ERROR! Syntax Error while loading YAML.


The error appears to have been in '/anywhere/tasks/main.yml': line 6, column 102, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

 - apt: name=elasticsearch update_cache=yes
 - lineinfile: dest="/etc/elasticsearch/elasticsearch.yml" regexp="# network.host" line='network.host: 0.0.0.0'
                                                                                                     ^ here
We could be wrong, but this one looks like it might be an issue with
unbalanced quotes.  If starting a value with a quote, make sure the
line ends with the same set of quotes.  For instance this arbitrary
example:

    foo: "bad" "wolf"

Could be written as:

    foo: '"bad" "wolf"'

Ansible failed to complete successfully. Any error output should be
visible above. Please fix these errors and try again.

対応

ダブルクオートで囲ってコロンだけ中括弧とクオートで囲むと動いた。

 - lineinfile: dest="/etc/elasticsearch/elasticsearch.yml" regexp="# network.ost" line="network.host{{':'}} 0.0.0.0"

環境

user@somehost:~/somewhere$ uname -a
Linux somehost 3.13.0-88-generic #135-Ubuntu SMP Wed Jun 8 21:10:42 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
user@somehost:~/somewhere$ ansible --version
ansible 2.1.0.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides
user@somehost:~/somewhere$ ansible-playbook --version
ansible-playbook 2.1.0.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides
user@somehost:~/somewhere$ vagrant --version
Vagrant 1.4.3

作業ログ

vagrant の provisioning です

user@somehost:~/somewhere$ vagrant provision [default] Running provisioner: ansible...
[DEPRECATION WARNING]: Instead of sudo/sudo_user, use become/become_user and 
make sure become_method is 'sudo' (default).
This feature will be removed in a 
future release. Deprecation warnings can be disabled by setting 
deprecation_warnings=False in ansible.cfg.
ERROR! Syntax Error while loading YAML.


The error appears to have been in '/anywhere/tasks/main.yml': line 6, column 102, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

 - apt: name=elasticsearch update_cache=yes
 - lineinfile: dest="/etc/elasticsearch/elasticsearch.yml" regexp="# network.host" line='network.host: 0.0.0.0'
                                                                                                     ^ here
We could be wrong, but this one looks like it might be an issue with
unbalanced quotes.  If starting a value with a quote, make sure the
line ends with the same set of quotes.  For instance this arbitrary
example:

    foo: "bad" "wolf"

Could be written as:

    foo: '"bad" "wolf"'

Ansible failed to complete successfully. Any error output should be
visible above. Please fix these errors and try again.

バックスラッシュ入れてもダメ

user@somehost:~/somewhere$ vagrant provision [default] Running provisioner: ansible...
[DEPRECATION WARNING]: Instead of sudo/sudo_user, use become/become_user and 
make sure become_method is 'sudo' (default).
This feature will be removed in a 
future release. Deprecation warnings can be disabled by setting 
deprecation_warnings=False in ansible.cfg.
ERROR! Syntax Error while loading YAML.


The error appears to have been in '/anyware/tasks/main.yml': line 6, column 103, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

 - apt: name=elasticsearch update_cache=yes
 - lineinfile: dest="/etc/elasticsearch/elasticsearch.yml" regexp="# network.host" line='network.host\: 0.0.0.0'
                                                                                                      ^ here
We could be wrong, but this one looks like it might be an issue with
unbalanced quotes.  If starting a value with a quote, make sure the
line ends with the same set of quotes.  For instance this arbitrary
example:

    foo: "bad" "wolf"

Could be written as:

    foo: '"bad" "wolf"'

Ansible failed to complete successfully. Any error output should be
visible above. Please fix these errors and try again.

クオートで囲って解決

user@somehost:~/somewhere$ vagrant provision [default] Running provisioner: ansible...
[DEPRECATION WARNING]: Instead of sudo/sudo_user, use become/become_user and 
make sure become_method is 'sudo' (default).
This feature will be removed in a 
future release. Deprecation warnings can be disabled by setting 
deprecation_warnings=False in ansible.cfg.

PLAY [all] *********************************************************************

TASK [setup] *******************************************************************
ok: [default]

コロンの後にスペースが入っているとエラーになるらしい

Ansible の YAML で「:」を使う方法 - Qiita