1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Ansible PlaybookにおいてYAMLフロー構文を使用する際に、[0]や['key']などが入っているとエラーとなりうる

1
Posted at

備忘

例えば、my_listが要素を持つリストの場合、以下は正常に実行可能なtasks

OK
- debug:
    var: my_list[0]

しかし、YAMLフロー構文を使用した以下はYAML構文レベルのエラーとなった

NG
- debug: { var: my_list[0] }

エラーの例

ERROR! We were unable to read either as JSON nor YAML, these are the errors we got from each:
JSON: Expecting value: line 2 column 1 (char 1)

Syntax Error while loading YAML.
  expected ',' or '}', but got '['

The error appears to be in '/xxxx/playbook.yml': line 9, column 26, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

  tasks:
  - debug: { var: my_list[0] }
                         ^ here

これは、[]がリストを表す記号であるため。
以下のように明示的に文字列とすれば問題なく実行可能。

OK
- debug: { var: "my_list[0]" }
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?