How to make EC2 instance join an ECS Cluster through Ansible Playbook?

I need to create an EC2 Instance and launch it to an existing ECS cluster. I know the same can be done manually through AWS console by executing following shell command on EC2 launch :

#!/bin/bash

echo ECS_CLUSTER=your_cluster_name >> /etc/ecs/ecs.config

How can i achieve the same using Ansible playbook?

You can use the ec2 module and pass the user data like this in the ec2 module:

user_data: |
#!/bin/sh
echo ECS_CLUSTER=your_cluster_name >> /etc/ecs/ecs.config

Thank You