I have tried to launch an ECS container instance using Ansible EC2 module.
My playbook is as follows.
- name: Launch ECS Container Instance
ec2:
key_name: "{{ ec2_keyname }}"
instance_type: t2.micro
image: ami-ca01d8ca
wait: yes
group: "{{ ec2_security_group }}"
region: ap-northeast-1
exact_count: 1
vpc_subnet_id: "{{ ec2_subnet_id }}"
count_tag:
docker-registry: 1
instance_profile_name: ecsInstanceRole
instance_tags:
Name: ECS_docker-registry
docker-registry: 1
assign_public_ip: yes
As a result, two instances launched; one of them is configured as I intend, but another has following tags that I don't intend to set.
- aws:autoscaling:groupName
- aws:cloudformation:logical-id
- aws:cloudformation:stack-id
- aws:cloudformation:stack-name
In addition, I can find these two instances on ECS dashboard.
But its only visible for the cluster "default", and invisible for other clusters.
What I really want to do is;
- Launch a ECS container instance
- Register the container instance to a cluster
It's better if I can do the process above with aws-cli, but first I should understand the strange behaviour of container instances and do manually.
You can also add an EC2 instance to an ECS cluster manually:
Create a file in /etc/ecs/ecs.config with this line:
Where {{ name }} is the cluster name you want.
The instance will create the cluster if it doesn't already exist.