A quick caveat about the folding >
operator that had me scratching my head for a while: the rows indented beneath it have to be at the same indentation level for the folding to happen correctly, at least when using Ansible.
I was converting an existing multi-line shell command that had \
line endings to escape newlines and had indented every row below the first one two spaces more. I used shell: >
, removed the backslashes and preserved the existing indentation.
The newlines were preserved, and I was losing my mind, because everywhere it said that >
should convert them to spaces.
See below for an example:
# Converts into ls -la /tmp, as expected
- name: working shell command that folds newlines
shell: >
ls
-la
/tmp
# Tries to run -la and /tmp as their own commands
- name: failing shell command that does not fold newlines
shell: >
ls
-la
/tmp
Hope this helps someone in a similar situation!