如何在 YAML 中连接字符串?

Roo*_*dra 5 yaml ansible ansible-playbook

我正在编写一个剧本,我需要在其中执行 mysql 查询并以 json 格式传递输出。剧本代码工作正常,只是我想在字符串concatenate部分遇到错误。如果我传递示例 json 字符串,它工作正常。

- name: Execute php script with json parameter
  command:  php -f /path/to/php/test.php "{'colors':{'red','blue','yellow'}}"
  register: php_output
Run Code Online (Sandbox Code Playgroud)

output.stdout_lines是已在我的剧本中设置的变量,其中包含{'red','blue','yellow'}格式输出。

- name: Execute php script with json parameter
  command:  php -f /path/to/php/test.php '{"stdout_lines": {{output.stdout_lines}} }'
  register: php_output
Run Code Online (Sandbox Code Playgroud)

那么如何output.stdout_lines在 中连接变量'{"stdout_lines": {{output.stdout_lines}} }'?有什么建议

Ale*_*dim 1

这会做

  - name: Generate JSON output based on template
    template: src=colors.json.j2 dest=/tmp/colors.json
    with_items: colors
Run Code Online (Sandbox Code Playgroud)

它将生成一个类似的文件

{'colors':
    {
        'blue',
        'red',
        'green',
        }
}
Run Code Online (Sandbox Code Playgroud)