0

I am trying to set docker log tag with Ansible for Amazon ECS TaskDefinition but unfortunately, I am getting an error mentioned below.

I exactly want to display the container name in the docker logs.

playbook.yml:

  tasks:
   - name: Create task definition
     ecs_taskdefinition:
       containers:
       - name: hello-world-1
         cpu: "2"
         essential: true
         image: "nginx"
         memory: "128"
         portMappings:
          - containerPort: "80"
            hostPort: "0"

         logConfiguration:
            logDriver: syslog
            options:
              syslog-address: udp://127.0.0.1:514
              tag: '{{.Name}}'
       family: "{{ taskfamily_name }}"
       state: present
     register: task_output

error:

TASK [Create task definition] ***************************************************************************
task path: /home/ubuntu/ansible/ecs_random.yml:14
fatal: [localhost]: FAILED! => {
    "msg": "template error while templating string: unexpected '.'. String: {{.Name}}"
}
mohit
  • 2,325
  • 23
  • 48

1 Answers1

0

Below expression works for me.

tag: "{{ '{{' }}.Name{{ '}}' }}"

task:

 tasks:
       - name: Create task definition
         ecs_taskdefinition:
           containers:
           - name: hello-world-1
             cpu: "2"
             essential: true
             image: "nginx"
             memory: "128"
             portMappings:
              - containerPort: "80"
                hostPort: "0"
             logConfiguration:
                logDriver: syslog
                options:
                  syslog-address: udp://127.0.0.1:514
                  tag: "{{ '{{' }}.Name{{ '}}' }}"

Related Question: Escaping double curly braces in Ansible

Related Documentation: http://jinja.pocoo.org/docs/dev/templates/#escaping

mohit
  • 2,325
  • 23
  • 48