Easy methods to Write Multiline Shell Scripts in Ansible


If you must write a shell script in Ansible, you most likely have one thing like this:

- title: iterate person teams
  shell: groupmod -o -g {{ merchandise['guid'] }} {{ merchandise['username'] }}
  with_items: "{{ customers }}"

However how do you write multiline shell scripts with this format?

Easy methods to write Multiline shell scripts

- title: iterate person teams
  shell: |
    groupmod -o -g {{ merchandise['guid'] }} {{ merchandise['username'] }} 
    do_some_stuff_here
    and_some_other_stuff
  with_items: "{{ customers }}"

Simply notice that Ansible can do some unusual issues with manipulations of arguments, so you could need to observe one thing like this:

- shell: |
    cat <<EOF
    It is a check.
    EOF

Or higher but, wrap them:

- shell:
    cmd: |
      cat <<EOF
      It is a check.
      EOF
See also  Episode 504: Frank McSherry on Materialize : Software program Engineering Radio

Leave a Reply