如何在多行上格式化长Ansible命令模块任务?

时间:2017-10-06 23:52:39

标签: ansible yaml

我正在尝试在多行上格式化以下命令任务。

tasks:
    ...
    - name: Run the python file
      command: "{{ lookup('env','HOME') }}/bin/pythonfile.py \"{{ cmd_status.stdout }}\" {{ test_number }}"

无格式化工作。 pythonfile已正确执行。我尝试使用>进行格式化:

tasks:
    ...
    - name: Run the python file
      command: >
        "{{ lookup('env','HOME') }}/bin/pythonfile.py \"{{ cmd_status.stdout }}\" {{ test_number }}"

它给出了:

  

" msg":" [Errno 2]没有这样的文件或目录",

Debug:
"invocation": {
    "module_args": {
        "_raw_params": "\"/home/bin/pythonfile.py

有关在多行上格式化命令行的任何建议。

1 个答案:

答案 0 :(得分:3)

简单地删除周围的引号:

command: >
  {{ lookup('env','HOME') }}/bin/pythonfile.py "{{ cmd_status.stdout }}" {{ test_number }}

否则整个字符串(包括空格和参数)被认为是要运行的可执行文件的名称(注意调试调用字符串中整行的\")。

当您在一行中编写时,首先会被YAML解析器解释并剥离。

相关问题