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.
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;
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.
To register an EC2 container instance in a ECS Cluster you have a few options:
Use special amazon-ecs-optimized AMI to manually launch EC2 instance with custom user data with awscli
or AWS Console (read more about Launching an Amazon ECS Container Instance ):
\n #!/bin/bash \n echo ECS_CLUSTER=your_cluster_name >> /etc/ecs/ecs.config \n
Use AWS OpsWorks and create ECS Cluster layer since AWS OpsWorks Supports Managing Amazon ECS Container Instances . In this case OpsWoks will any EC2 instance within a layer to work with particular ECS Cluster.
There are few limitations:
You can also add an EC2 instance to an ECS cluster manually:
Create a file in /etc/ecs/ecs.config with this line:
ECS_CLUSTER={{ name }}
Where {{ name }} is the cluster name you want.
The instance will create the cluster if it doesn't already exist.
You can try looking into using user_data
field of the ec2 module.
https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/user-data.html
You will need to have the following in ecs.config
before the ecs agent starts up.
#!/bin/bash
echo ECS_CLUSTER=your_cluster_name >> /etc/ecs/ecs.config
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.