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

**URL:** <https://forum.ansible.com/t/how-to-make-ec2-instance-join-an-ecs-cluster-through-ansible-playbook/26447>\
**Category:** Ansible Project\
**Tags:** aws\
**Created:** [January 10, 2018, 7:04am UTC](https://forum.ansible.com/t/how-to-make-ec2-instance-join-an-ecs-cluster-through-ansible-playbook/26447 "2018-01-10T07:04:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jacob.oommen](https://avatars.discourse-cdn.com/v4/letter/j/278dde/32.png) [@jacob.oommen](https://forum.ansible.com/u/jacob.oommen)\
**Post date:** [January 10, 2018, 7:04am UTC](https://forum.ansible.com/t/how-to-make-ec2-instance-join-an-ecs-cluster-through-ansible-playbook/26447/1 "2018-01-10T07:04:30Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Arbab\_Nazar1](https://avatars.discourse-cdn.com/v4/letter/a/3e96dc/32.png) [@Arbab\_Nazar1](https://forum.ansible.com/u/Arbab_Nazar1)\
**Post date:** [January 10, 2018, 10:22pm UTC](https://forum.ansible.com/t/how-to-make-ec2-instance-join-an-ecs-cluster-through-ansible-playbook/26447/2 "2018-01-10T22:22:17Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jacob.oommen](https://avatars.discourse-cdn.com/v4/letter/j/278dde/32.png) [@jacob.oommen](https://forum.ansible.com/u/jacob.oommen)\
**Post date:** [January 12, 2018, 6:16am UTC](https://forum.ansible.com/t/how-to-make-ec2-instance-join-an-ecs-cluster-through-ansible-playbook/26447/3 "2018-01-12T06:16:20Z")

</div>

Thank You
