community.aws.ecs_taskdefinition module – register a task definition in ecs
Note
This module is part of the community.aws collection (version 2.6.1).
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
.
To use it in a playbook, specify: community.aws.ecs_taskdefinition
.
New in version 1.0.0: of community.aws
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.15.0
botocore >= 1.18.0
Parameters
Parameter |
Comments |
---|---|
The ARN of the task description to delete. |
|
If profile is set this parameter is ignored. Passing the aws_access_key and profile options at the same time has been deprecated and the options will be made mutually exclusive after 2022-06-01. |
|
The location of a CA Bundle to use when validating SSL certificates. Not used by boto 2 based modules. Note: The CA Bundle is read ‘module’ side and may need to be explicitly copied from the controller if not run locally. |
|
A dictionary to modify the botocore configuration. Parameters can be found at https://botocore.amazonaws.com/v1/documentation/api/latest/reference/config.html#botocore.config.Config. Only the ‘user_agent’ key is used for boto modules. See http://boto.cloudhackers.com/en/latest/boto_config_tut.html#boto for more boto configuration. |
|
If profile is set this parameter is ignored. Passing the aws_secret_key and profile options at the same time has been deprecated and the options will be made mutually exclusive after 2022-06-01. |
|
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 health check command and associated configuration parameters for the container. |
|
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 botocore.endpoint logger to parse the unique (rather than total) “resource:action” API calls made during a task, outputing the set to the resource_actions key in the task results. Use the aws_resource_action callback to output to total list made during a playbook. The ANSIBLE_DEBUG_BOTOCORE_LOGS environment variable may also be used. Choices:
|
|
URL to use to connect to EC2 or your Eucalyptus cloud (by default the module will use EC2 endpoints). Ignored for modules where region is required. Must be specified for all other modules if region is not used. If not set then the value of the EC2_URL environment variable, if any, is used. |
|
The Amazon Resource Name (ARN) of the task execution role that the Amazon ECS container agent and the Docker daemon can assume. |
|
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. |
|
Using profile will override aws_access_key, aws_secret_key and security_token and support for passing them at the same time as profile has been deprecated. aws_access_key, aws_secret_key and security_token will be made mutually exclusive with profile after 2022-06-01. |
|
The AWS region to use. If not specified then the value of the AWS_REGION or EC2_REGION environment variable, if any, is used. See http://docs.aws.amazon.com/general/latest/gr/rande.html#ec2_region |
|
A revision number for the task definition. |
|
If profile is set this parameter is ignored. Passing the security_token and profile options at the same time has been deprecated and the options will be made mutually exclusive after 2022-06-01. |
|
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. |
|
When set to “no”, SSL certificates will not be validated for communication with the AWS APIs. Choices:
|
|
A list of names of volumes to be attached. |
|
The name of the volume. |
Notes
Note
If parameters are not set within the module, the following environment variables can be used in decreasing order of precedence
AWS_URL
orEC2_URL
,AWS_PROFILE
orAWS_DEFAULT_PROFILE
,AWS_ACCESS_KEY_ID
orAWS_ACCESS_KEY
orEC2_ACCESS_KEY
,AWS_SECRET_ACCESS_KEY
orAWS_SECRET_KEY
orEC2_SECRET_KEY
,AWS_SECURITY_TOKEN
orEC2_SECURITY_TOKEN
,AWS_REGION
orEC2_REGION
,AWS_CA_BUNDLE
When no credentials are explicitly provided the AWS SDK (boto3) that Ansible uses will fall back to its configuration files (typically
~/.aws/credentials
). See https://boto3.amazonaws.com/v1/documentation/api/latest/guide/credentials.html for more information.Modules based on the original AWS SDK (boto) may read their default configuration from different files. See https://boto.readthedocs.io/en/latest/boto_config_tut.html for more information.
AWS_REGION
orEC2_REGION
can be typically be used to specify the AWS region, when required, but this can also be defined in the configuration files.
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
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 |
Authors
Mark Chance (@Java1Guy)
Alina Buzachis (@alinabuzachis)