"here doc" in shell command

I am trying to use a “here doc” in a shell command like so:

  • name: frustration
    shell: |
    cat <<-EOF | my_program
    input line 1
    input line 2
    EOF
    another_program

along with a number of permutations, all of which have resulted in “bash: line 3: warning: here-document at line 0 delimited by end-of-file (wanted `EOF’)”.

I found this:
https://github.com/ansible/ansible/issues/12856
which seems to imply there is some way to accomplish what I’m trying do but I can’t understand how, nor do I see anything else relevant in the Ansible docs or Google.

What is the magic syntax for the above?

`

  • name: fun fun fun
    shell:
    cmd: |
    #!/bin/bash
    SCRIPT=$(cat <<EOF
    echo “hello world!”
    EOF
    )
    ${SCRIPT}

`

Solution found here: https://stackoverflow.com/questions/40230184/how-to-do-multiline-shell-script-in-ansible

Ah, thank you very much! I actually had seen that SO post before but realize now when I tried it I screwed up (I had left the vertical bar character on the “shell” line, not the command line.) Now I see it does in fact work.

But one further question… Where is “cmd” documented?

Good point. It’s seems not officially documented. In my local Ansible installation I’ve found the relating code part
in playbook/tasks.py

`

182 # the command/shell/script modules used to support the cmd arg,
183 # which corresponds to what we now call _raw_params, so move that
184 # value over to _raw_params (assuming it is empty)
185 if action in (‘command’, ‘shell’, ‘script’):
186 if ‘cmd’ in args:
187 if args.get(‘_raw_params’, ‘’) != ‘’:
188 raise AnsibleError(“The ‘cmd’ argument cannot be used when other raw parameters are specified.”
189 " Please put everything in one or the other place.", obj=ds)
190 args[‘_raw_params’] = args.pop(‘cmd’)

`