PARALLAX

ecs_taskdefinition

register a task definition in ecs

Collection: community.aws

Full Name: community.aws.ecs_taskdefinition

Synopsis

register a task definition in ecs

Parameters

NameTypeRequiredDefaultDescription
access_keystr
arnstr
aws_ca_bundlepath
aws_configdict
containerslistyes
cpustr
debug_botocore_endpoint_logsboolfalse
endpoint_urlstr
execution_role_arnstr
familystr
force_createboolfalse
launch_typestr
memorystr
network_modestrbridge
placement_constraintslist
profilestr
regionstr
revisionint
runtime_platformdictmap[cpuArchitecture:X86_64 operatingSystemFamily:LINUX]
secret_keystr
session_tokenstr
statestryes
task_role_arnstr
validate_certsbooltrue
volumeslist

Example

yaml
- 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
Search
    ↑ ↓ move↵ openesc close