如何使用ansible ecs_task_definition模块设置docker日志驱动程序标记?

时间:2018-04-17 10:44:19

标签: docker ansible amazon-ecs

我正在尝试使用Ansible为Amazon ECS TaskDefinition设置docker日志标记但不幸的是,我收到了下面提到的错误。

我确实想在docker日志中显示容器名称。

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

错误:

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}}"
}

1 个答案:

答案 0 :(得分:0)

下面的表达对我有用。

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

任务:

 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{{ '}}' }}"
  

相关问题:   Escaping double curly braces in Ansible

     

相关文档:   http://jinja.pocoo.org/docs/dev/templates/#escaping