【发布时间】:2014-03-12 11:00:50
【问题描述】:
我正在编写一个剧本,我需要在其中执行 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
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
那么如何在 '{"stdout_lines": {{output.stdout_lines}} }' 中连接 output.stdout_lines 变量?任何建议
【问题讨论】:
-
当你在 Ansible 任务上传递一个数组时,它将为数组上的每个条目执行一次。它不会像您假设的那样在执行期间连接值。看看docs.ansible.com/playbooks_loops.html
标签: yaml ansible ansible-playbook