的無效類型我有幾個服務在Amazon ECS上的docker容器中運行,並且正在爲每個服務分配總系統內存的百分比。Ansible,Boto,AWS - 參數containerDefinitions [0] .memory
在我ansible /角色/ ecs_cluster_init /默認/ main.yaml文件我有以下項目:
docker_memory_limit_service1: 17
docker_memory_limit_service2: 12
docker_memory_limit_service3: 16
docker_memory_limit_service4: 10
docker_memory_limit_service5: 16
docker_memory_limit_service6: 10
total_system_memory : 2048
服務1應該得到的系統總內存的17%,而服務4只得到10%。這很容易適應實例大小的變化。
以我ansible /角色/ ecs_cluster_init/VARS/main.yaml文件I具有(部分部分):
ecs_task_definitions:
- name: "service1"
elb: "{{ elb_creation_output.results[0].elb.dns_name }}"
image: "{{ service1_docker_image }}"
port: "{{ ports.service1 }}"
memory: "{{ (total_system_memory * (docker_memory_limit_service1|int/100))|int|abs }}"
爲了確保清楚起見,服務存儲值變成一個百分比(除以100 ),然後確定整個系統內存的那部分。
在我ansible /角色/ ecs_cluster_init /任務/ main.yaml文件我有:
## ECS Task and Service Definitions
- block:
- name: Create ECS Service1 Task Definitions
ecs_taskdefinition:
region: "{{ region }}"
containers:
- name: "{{ item.name }}"
cpu: 0
essential: true
image: "{{ item.image }}"
memory: {{ item.memory|int|abs }}
mountPoints: "{{ item.mounts }}"
environment: "{{ item.env_vars }}"
portMappings: "{{ item.portmap }}"
entryPoint:
- "java"
- "-Xms{{ java_heap_size_initial }}"
- "-Xmx{{ java_heap_size_max }}"
- "-DlogDir=/host"
- "-Dcom.sun.net.ssl.checkRevocation=false"
- "-jar"
- "/app.jar"
logConfiguration:
logDriver: "{{ ecs_task_log_configuration.logDriver }}"
options:
max-size: "{{ ecs_task_log_configuration.options.max_size }}"
max-file: "{{ ecs_task_log_configuration.options.max_file }}"
family: "{{ service_prefix }}-{{ item.name }}-{{ env_name }}"
state: present
increment_revision: true
volumes: "{{ item.volumes }}"
register: service1_task_definition
with_items: "{{ ecs_task_definitions }}"
當我運行我收到以下錯誤的作用劇本:
TASK [ecs_cluster_create : Create ECS Service1 Task Definitions] ****************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: Invalid type for parameter containerDefinitions[0].memory, value: 204, type: <type 'str'>, valid types: <type 'int'>, <type 'long'>
任何想知道我做錯了什麼或我缺少指定內存值應該是一個int?
您可以嘗試添加'| to_json'過濾器'{{item.memory | int | to_json}}' – Vor
在應用您的建議後,我仍收到相同的錯誤消息。 –