Run a one off ECS task via ansible

I have a docker image that exists in an Amazon ECR repository. The docker image runs a mysqldump and then copies the file to an s3 bucket. It would run the shell script below:

#!/bin/bash
now=$(date +"%m_%d_%Y")
BACKUP_FILE="backup_$now.gz"
time mysqldump --force --host $DB_HOST --user $DB_USERNAME -p$DB_PASSWORD $DB | gzip -9 > /app/shared_volume/tmp/$BACKUP_FILE
aws s3 cp /app/shared_volume/tmp/$BACKUP_FILE s3://abucketforbackups/$BACKUP_FILE
rm $BACKUP_FILE

I would like to write an ansible playbook that does the following:

  • Creates a task that instantiates the container from the ECR
  • Run the script inside the container
  • stops and removes the container

Source: StackOverflow