2

I am trying to format following command tasks over multiple lines.

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

Works without formatting. pythonfile is executed properly. I tried formatting with >:

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

and it gives:

"msg": "[Errno 2] No such file or directory",

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

Any suggestions on formatting the command line over multiple lines.

2
  • The problem is still visible in the -vvv results, but the value is stripped. For clarity you should include the whole _raw_params. Commented Oct 7, 2017 at 1:48
  • YAML has good options for this. It's not specific to Ansible. YAML Multiline Commented Jan 13, 2023 at 19:29

1 Answer 1

5

Simply drop the surrounding quotes:

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

Otherwise the whole string (including spaces and arguments) is considered to be the name of the executable to run (notice \" surrounding the whole line in the debug invocation string).

When you write it in a single line, the gets first interpreted and stripped by YAML parser.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.