# Multi line Shell script in ansible shell module.

**URL:** <https://forum.ansible.com/t/multi-line-shell-script-in-ansible-shell-module/28137>\
**Category:** Ansible Project\
**Tags:** aws\
**Created:** [July 24, 2018, 5:00pm UTC](https://forum.ansible.com/t/multi-line-shell-script-in-ansible-shell-module/28137 "2018-07-24T17:00:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tharun.kumarc09](https://avatars.discourse-cdn.com/v4/letter/t/dbc845/32.png) [@tharun.kumarc09](https://forum.ansible.com/u/tharun.kumarc09)\
**Post date:** [July 24, 2018, 5:00pm UTC](https://forum.ansible.com/t/multi-line-shell-script-in-ansible-shell-module/28137/1 "2018-07-24T17:00:15Z")

</div>

I am a newbie with ansible. Currently i have shell script to purge the rds snapshots if expiration tag is matching the current date.

This is how script looks like:

#!/bin/bash

date=$(date +%F)  
echo $date

get\_rds() {  
aws rds describe-db-snapshots --snapshot-type manual --query “DBSnapshots.[DBSnapshotArn]” --output text  
}

remove\_rds\_using\_tags() {  
expire=$(aws rds list-tags-for-resource --resource-name “$1” --query ‘TagList[?Key==`expiration`].Value’)  
if [“$expire” != “”]  
then  
expire=$(echo $expire | cut -c4-)  
echo $expire  
expire=${expire:0:-3}  
echo $expire  
if [“$expire” == “$date”]  
then  
echo “Expiration date matching the current date… Proceeding with Purging”  
snapshotid=$(echo “$1” | rev | cut -d’:’ -f1 | rev)  
echo $snapshotid  
aws rds delete-db-snapshot --db-snapshot-identifier $snapshotid  
else  
echo “Expiration date not matching the current date”  
fi  
else  
echo “No expiration tag for the snapshot”  
fi

}

for id in $(get\_rds)  
do  
echo $id  
remove\_rds\_using\_tags $id  
echo “”  
done

Please let me know how to use these multiline shell script in ansible using ansible shell module

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [July 24, 2018, 4:56am UTC](https://forum.ansible.com/t/multi-line-shell-script-in-ansible-shell-module/28137/2 "2018-07-24T04:56:23Z")

</div>

what you really want to do is use the script module  
[https://docs.ansible.com/ansible/latest/plugins/inventory/script.html](https://docs.ansible.com/ansible/latest/plugins/inventory/script.html)

---

<div class="post-metadata">

**Author:** ![Tchia04](https://avatars.discourse-cdn.com/v4/letter/t/fbc32d/32.png) [@Tchia04](https://forum.ansible.com/u/Tchia04)\
**Post date:** [July 25, 2018, 4:19am UTC](https://forum.ansible.com/t/multi-line-shell-script-in-ansible-shell-module/28137/3 "2018-07-25T04:19:08Z")

</div>

The correct link for the script module is [https://docs.ansible.com/ansible/2.5/modules/script\_module.html](https://docs.ansible.com/ansible/2.5/modules/script_module.html)

The previous link is for the script plugin.

–Tony Chia
