2017-10-06 51 views
1

我想通過多行格式化下面的命令任務。如何通過多行格式化一個長的Ansible命令模塊任務?

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 }}" 

,它給:

「味精」: 「[錯誤2]沒有這樣的文件或目錄」,

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

任何建議在多行上格式化命令行。

+0

該問題在'-vvv'結果中仍然可見,但該值被剝離。爲了清楚起見,你應該包含整個'_raw_params'。 – techraf

回答

1

只需拖放周圍的報價:

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

否則整個字符串(包括空格和參數)被認爲是可執行的周圍在調試調用串整條生產線的名稱來運行(注意\" )。

當你把它寫在一行中時,首先被YAML解析器解釋和解析。