備忘
例えば、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]" }