community.aws.ecs_taskdefinition module – register a task definition in ecs
Note
This module is part of the community.aws collection (version 8.0.0).
You might already have this collection installed if you are using the ansible
package.
It is not included in ansible-core
.
To check whether it is installed, run ansible-galaxy collection list
.
To install it, use: ansible-galaxy collection install community.aws
.
You need further requirements to be able to use this module,
see Requirements for details.
To use it in a playbook, specify: community.aws.ecs_taskdefinition
.
New in community.aws 1.0.0
Synopsis
Registers or deregisters task definitions in the Amazon Web Services (AWS) EC2 Container Service (ECS).
Requirements
The below requirements are needed on the host that executes this module.
python >= 3.6
boto3 >= 1.26.0
botocore >= 1.29.0
Parameters
Parameter |
Comments |
---|---|
AWS access key ID. See the AWS documentation for more information about access tokens https://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html#access-keys-and-secret-access-keys. The The aws_access_key and profile options are mutually exclusive. The aws_access_key_id alias was added in release 5.1.0 for consistency with the AWS botocore SDK. The ec2_access_key alias has been deprecated and will be removed in a release after 2024-12-01. Support for the |
|
The ARN of the task description to delete. |
|
The location of a CA Bundle to use when validating SSL certificates. The |
|
A dictionary to modify the botocore configuration. Parameters can be found in the AWS documentation https://botocore.amazonaws.com/v1/documentation/api/latest/reference/config.html#botocore.config.Config. |
|
A list of containers definitions. See https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ecs.html for a complete list of parameters. |
|
The command that is passed to the container. If there are multiple arguments, each argument is a separated string in the array. |
|
The number of cpu units reserved for the container. |
|
The dependencies defined for container startup and shutdown. When a dependency is defined for container startup, for container shutdown it is reversed. |
|
The dependency condition of the container. Choices:
|
|
The name of a container. |
|
When this parameter is Choices:
|
|
A list of DNS search domains that are presented to the container. This parameter is not supported for Windows containers. |
|
A list of DNS servers that are presented to the container. This parameter is not supported for Windows containers. |
|
A key/value map of labels to add to the container. |
|
A list of strings to provide custom labels for SELinux and AppArmor multi-level security systems. This parameter is not supported for Windows containers. |
|
The entry point that is passed to the container. |
|
The environment variables to pass to a container. |
|
The name of the key-value pair. |
|
The value of the key-value pair. |
|
A list of files containing the environment variables to pass to a container. |
|
The file type to use. The only supported value is |
|
The Amazon Resource Name (ARN) of the Amazon S3 object containing the environment variable file. |
|
If essential=True, and the container fails or stops for any reason, all other containers that are part of the task are stopped. Choices:
|
|
A list of hostnames and IP address mappings to append to the /etc/hosts file on the container. This parameter is not supported for Windows containers or tasks that use network_mode=awsvpc. |
|
The hostname to use in the /etc/hosts entry. |
|
The IP address to use in the /etc/hosts entry. |
|
The FireLens configuration for the container. This is used to specify and configure a log router for container logs. |
|
The options to use when configuring the log router. This field is optional and can be used to specify a custom configuration file or to add additional metadata, such as the task, task definition, cluster, and container instance details to the log event. If specified, the syntax to use is For more information, see https://docs.aws.amazon.com/AmazonECS/latest/developerguide/using_firelens.html#firelens-taskdef. |
|
The log router to use. The valid values are Choices:
|
|
The health check command and associated configuration parameters for the container. |
|
A string array representing the command that the container runs to determine if it is healthy. The string array must start with CMD to run the command arguments directly, or CMD-SHELL to run the command with the container’s default shell. An exit code of 0 indicates success, and non-zero exit code indicates failure. |
|
The time period in seconds between each health check execution. You may specify between 5 and 300 seconds. The default value is 30 seconds. Default: |
|
The number of times to retry a failed health check before the container is considered unhealthy. You may specify between 1 and 10 retries. The default value is 3. Default: |
|
The optional grace period to provide containers time to bootstrap before failed health checks count towards the maximum number of retries. You can specify between 0 and 300 seconds. By default, the startPeriod is disabled. Note: If a health check succeeds within the startPeriod, then the container is considered healthy and any subsequent failures count toward the maximum number of retries. |
|
The time period in seconds to wait for a health check to succeed before it is considered a failure. You may specify between 2 and 60 seconds. The default value is 5. Default: |
|
The hostname to use for your container. This parameter is not supported if network_mode=awsvpc. |
|
The image used to start a container. |
|
When interactive=True, it allows to deploy containerized applications that require stdin or a tty to be allocated. Choices:
|
|
Allows containers to communicate with each other without the need for port mappings. This parameter is only supported if network_mode=bridge. |
|
Linux-specific modifications that are applied to the container, such as Linux kernel capabilities. |
|
The Linux capabilities for the container that are added to or dropped from the default configuration provided by Docker. |
|
The Linux capabilities for the container that have been added to the default configuration provided by Docker. If launch_type=FARGATE, this parameter is not supported. Choices:
|
|
The Linux capabilities for the container that have been removed from the default configuration provided by Docker. Choices:
|
|
Any host devices to expose to the container. If launch_type=FARGATE, this parameter is not supported. |
|
The path inside the container at which to expose the host device. |
|
The path for the device on the host container instance. |
|
The explicit permissions to provide to the container for the device. |
|
Run an init process inside the container that forwards signals and reaps processes. Choices:
|
|
The total amount of swap memory (in MiB) a container can use. If launch_type=FARGATE, this parameter is not supported. |
|
The value for the size (in MiB) of the /dev/shm volume. If launch_type=FARGATE, this parameter is not supported. |
|
This allows you to tune a container’s memory swappiness behavior. If launch_type=FARGATE, this parameter is not supported. |
|
The container path, mount options, and size (in MiB) of the tmpfs mount. If launch_type=FARGATE, this parameter is not supported. |
|
The absolute file path where the tmpfs volume is to be mounted. |
|
The list of tmpfs volume mount options. Choices:
|
|
The size (in MiB) of the tmpfs volume. |
|
The log configuration specification for the container. |
|
The log driver to use for the container. For tasks on AWS Fargate, the supported log drivers are For tasks hosted on Amazon EC2 instances, the supported log drivers are |
|
The amount (in MiB) of memory to present to the container. |
|
The soft limit (in MiB) of memory to reserve for the container. |
|
The mount points for data volumes in your container. |
|
The path on the container to mount the host volume at. |
|
If this value is If this value is Choices:
|
|
The name of the volume to mount. |
|
The name of a container. |
|
The configuration options to send to the log driver. |
|
The list of port mappings for the container. |
|
The port number on the container that is bound to the user-specified or automatically assigned host port. |
|
The port number on the container instance to reserve for your container. |
|
The protocol used for the port mapping. Choices:
|
|
When this parameter is Choices:
|
|
When this parameter is Choices:
|
|
When this parameter is Choices:
|
|
The private repository authentication credentials to use. |
|
The Amazon Resource Name (ARN) of the secret containing the private repository credentials. |
|
The type and amount of a resource to assign to a container. The only supported resources are |
|
The type of resource to assign to a container. Choices:
|
|
The value for the specified resource type. |
|
The secrets to pass to the log configuration. |
|
The name of the secret. |
|
The secret to expose to the container. |
|
The secrets to pass to the container. |
|
The value to set as the environment variable on the container. |
|
The secret to expose to the container. |
|
Time duration (in seconds) to wait before giving up on resolving dependencies for a container. |
|
Time duration (in seconds) to wait before the container is forcefully killed if it doesn’t exit normally on its own. |
|
A list of namespaced kernel parameters to set in the container. |
|
The namespaced kernel parameter to set a |
|
The value for the namespaced kernel parameter that’s specified in |
|
A list of ulimits to set in the container. This parameter is not supported for Windows containers. |
|
The hard limit for the ulimit type. |
|
The type of the ulimit. Choices:
|
|
The soft limit for the ulimit type. |
|
The user to use inside the container. This parameter is not supported for Windows containers. |
|
Data volumes to mount from another container. |
|
If this value is If this value is Choices:
|
|
The name of another container within the same task definition from which to mount volumes. |
|
The working directory in which to run commands inside the container. |
|
The number of cpu units used by the task. If launch_type=EC2, this field is optional and any value can be used. If launch_type=FARGATE, this field is required and you must use one of |
|
Use a The Choices:
|
|
URL to connect to instead of the default AWS endpoints. While this can be used to connection to other AWS-compatible services the amazon.aws and community.aws collections are only tested against AWS. The The ec2_url and s3_url aliases have been deprecated and will be removed in a release after 2024-12-01. Support for the |
|
The Amazon Resource Name (ARN) of the task execution role that the Amazon ECS container agent and the Docker daemon can assume. Default: |
|
A Name that would be given to the task definition. |
|
Always create new task definition. Choices:
|
|
The launch type on which to run your task. Choices:
|
|
The amount (in MiB) of memory used by the task. If launch_type=EC2, this field is optional and any value can be used. If launch_type=FARGATE, this field is required and is limited by the CPU. |
|
The Docker networking mode to use for the containers in the task. Windows containers must use network_mode=default, which will utilize docker NAT networking. Setting network_mode=default for a Linux container will use Choices:
|
|
Placement constraint objects to use for the task. You can specify a maximum of 10 constraints per task. Task placement constraints are not supported for tasks run on Fargate. |
|
A cluster query language expression to apply to the constraint. |
|
The type of constraint. |
|
A named AWS profile to use for authentication. See the AWS documentation for more information about named profiles https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html. The The profile option is mutually exclusive with the aws_access_key, aws_secret_key and security_token options. |
|
The AWS region to use. For global services such as IAM, Route53 and CloudFront, region is ignored. The See the Amazon AWS documentation for more information http://docs.aws.amazon.com/general/latest/gr/rande.html#ec2_region. The Support for the |
|
A revision number for the task definition. |
|
runtime platform configuration for the task Default: |
|
The CPU Architecture type to be used by the task Choices:
|
|
OS type to be used by the task Choices:
|
|
AWS secret access key. See the AWS documentation for more information about access tokens https://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html#access-keys-and-secret-access-keys. The The secret_key and profile options are mutually exclusive. The aws_secret_access_key alias was added in release 5.1.0 for consistency with the AWS botocore SDK. The ec2_secret_key alias has been deprecated and will be removed in a release after 2024-12-01. Support for the |
|
AWS STS session token for use with temporary credentials. See the AWS documentation for more information about access tokens https://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html#access-keys-and-secret-access-keys. The The security_token and profile options are mutually exclusive. Aliases aws_session_token and session_token were added in release 3.2.0, with the parameter being renamed from security_token to session_token in release 6.0.0. The security_token, aws_security_token, and access_token aliases have been deprecated and will be removed in a release after 2024-12-01. Support for the |
|
State whether the task definition should exist or be deleted. Choices:
|
|
The Amazon Resource Name (ARN) of the IAM role that containers in this task can assume. All containers in this task are granted the permissions that are specified in this role. Default: |
|
When set to Setting validate_certs=false is strongly discouraged, as an alternative, consider setting aws_ca_bundle instead. Choices:
|
|
A list of names of volumes to be attached. |
|
The name of the volume. |
Notes
Note
Caution: For modules, environment variables and configuration files are read from the Ansible ‘host’ context and not the ‘controller’ context. As such, files may need to be explicitly copied to the ‘host’. For lookup and connection plugins, environment variables and configuration files are read from the Ansible ‘controller’ context and not the ‘host’ context.
The AWS SDK (boto3) that Ansible uses may also read defaults for credentials and other settings, such as the region, from its configuration files in the Ansible ‘host’ context (typically
~/.aws/credentials
). See https://boto3.amazonaws.com/v1/documentation/api/latest/guide/credentials.html for more information.
Examples
- name: Create task definition
community.aws.ecs_taskdefinition:
containers:
- name: simple-app
cpu: 10
essential: true
image: "httpd:2.4"
memory: 300
mountPoints:
- containerPath: /usr/local/apache2/htdocs
sourceVolume: my-vol
portMappings:
- containerPort: 80
hostPort: 80
logConfiguration:
logDriver: awslogs
options:
awslogs-group: /ecs/test-cluster-taskdef
awslogs-region: us-west-2
awslogs-stream-prefix: ecs
- name: busybox
command:
- >
/bin/sh -c "while true; do echo '<html><head><title>Amazon ECS Sample App</title></head><body><div><h1>Amazon ECS Sample App</h1>
<h2>Congratulations!</h2>
<p>Your application is now running on a container in Amazon ECS.</p>' > top; /bin/date > date ; echo '</div></body></html>' > bottom;
cat top date bottom > /usr/local/apache2/htdocs/index.html ; sleep 1; done"
cpu: 10
entryPoint:
- sh
- "-c"
essential: false
image: busybox
memory: 200
volumesFrom:
- sourceContainer: simple-app
volumes:
- name: my-vol
family: test-cluster-taskdef
state: present
register: task_output
- name: Create task definition
community.aws.ecs_taskdefinition:
family: nginx
containers:
- name: nginx
essential: true
image: "nginx"
portMappings:
- containerPort: 8080
hostPort: 8080
cpu: 512
memory: 1024
state: present
- name: Create task definition
community.aws.ecs_taskdefinition:
family: nginx
containers:
- name: nginx
essential: true
image: "nginx"
portMappings:
- containerPort: 8080
hostPort: 8080
launch_type: FARGATE
cpu: 512
memory: 1024
state: present
network_mode: awsvpc
- name: Create task definition
community.aws.ecs_taskdefinition:
family: nginx
containers:
- name: nginx
essential: true
image: "nginx"
portMappings:
- containerPort: 8080
hostPort: 8080
cpu: 512
memory: 1024
dependsOn:
- containerName: "simple-app"
condition: "start"
# Create Task Definition with Environment Variables and Secrets
- name: Create task definition
community.aws.ecs_taskdefinition:
family: nginx
containers:
- name: nginx
essential: true
image: "nginx"
environment:
- name: "PORT"
value: "8080"
secrets:
# For variables stored in Secrets Manager
- name: "NGINX_HOST"
valueFrom: "arn:aws:secretsmanager:us-west-2:123456789012:secret:nginx/NGINX_HOST"
# For variables stored in Parameter Store
- name: "API_KEY"
valueFrom: "arn:aws:ssm:us-west-2:123456789012:parameter/nginx/API_KEY"
launch_type: FARGATE
cpu: 512
memory: 1GB
state: present
network_mode: awsvpc
# Create Task Definition with health check
- name: Create task definition
community.aws.ecs_taskdefinition:
family: nginx
containers:
- name: nginx
essential: true
image: "nginx"
portMappings:
- containerPort: 8080
hostPort: 8080
cpu: 512
memory: 1024
healthCheck:
command:
- CMD-SHELL
- /app/healthcheck.py
interval: 60
retries: 3
startPeriod: 15
timeout: 15
state: present
Return Values
Common return values are documented here, the following are the fields unique to this module:
Key |
Description |
---|---|
a reflection of the input parameters Returned: always |