Thursday, March 9, 2023
HomeSoftware EngineeringThe way to Write Multiline Shell Scripts in Ansible

The way to Write Multiline Shell Scripts in Ansible


If you have to write a shell script in Ansible, you in all probability have one thing like this:

- identify: 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?

The way to write Multiline shell scripts

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

Simply word that Ansible can do some unusual issues with manipulations of arguments, so you could wish to comply with one thing like this:

- shell: |
    cat <<EOF
    It is a take a look at.
    EOF

Or higher but, wrap them:

- shell:
    cmd: |
      cat <<EOF
      It is a take a look at.
      EOF

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments