amazon-web-services - 安西布尔。创建不同的 ec2 实例错误:最小实例计数必须大于零
问题描述
我尝试创建几个具有不同计数和标签的 ec2 实例。3 Webserver 实例部署。但是一个负载均衡器给出了一条错误消息:
`TASK [createIns_ec2 : Provision instance(s)] *******************************************************************************************
ok: [localhost] => (item={'value': {u'count': 3}, 'key': u'webserver'})
failed: [localhost] (item={'value': {u'count': 1}, 'key': u'lb'}) => {"ansible_loop_var": "item", "changed": false, "item": {"key": "lb", "value": {"count": 1}}, "msg": "Instance creation failed => InvalidParameterValue: Minimum instance count must be greater than zero"}
`
我如何在没有重复 ec2 代码块的情况下创建不同的实例,或者如何解决这个问题?
剧本的一部分
- name: add ec2 variables
include_vars:
file: ../../../group_vars/main.yml
- name: Provision instance(s)
ec2:
aws_access_key: "{{ec2_access_key}}"
aws_secret_key: "{{ec2_secret_key}}"
key_name: "{{ key_name }}"
id: "{{ id }}"
group_id: "{{ result_sec_group.group_id }}"
image: "{{ image }}"
instance_type: t2.micro
region: "{{ region }}"
wait: true
instance_tags:
Name: "{{ item.key }}"
count: "{{ item.value.count }}"
with_dict: "{{ EC2_VMS }}"`
vars 文件的一部分
region: eu-central-1
image: ami-0cc0a36f626a4fdf5
EC2_VMS:
lb:
count: 1
webserver:
count: 3
`
此任务的调试日志
TASK [createIns_ec2 : Provision instance(s)] *******************************************************************************************
task path: /home/arudy/playbooks/site/roles/createIns_ec2/tasks/main.yml:36
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: root
<127.0.0.1> EXEC /bin/sh -c 'echo ~root && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /root/.ansible/tmp/ansible-tmp-1575982751.31-38290473535447 `" && echo ansible-tmp-1575982751.31-38290473535447="` echo /root/.ansible/tmp/ansible-tmp-1575982751.31-38290473535447 `" ) && sleep 0'
Using module file /usr/lib/python2.7/dist-packages/ansible/modules/cloud/amazon/ec2.py
<127.0.0.1> PUT /home/arudy/.ansible/tmp/ansible-local-21511yOIVIE/tmpUGZTpJ TO /root/.ansible/tmp/ansible-tmp-1575982751.31-38290473535447/AnsiballZ_ec2.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-tmp-1575982751.31-38290473535447/ /root/.ansible/tmp/ansible-tmp-1575982751.31-38290473535447/AnsiballZ_ec2.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python2 /root/.ansible/tmp/ansible-tmp-1575982751.31-38290473535447/AnsiballZ_ec2.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /root/.ansible/tmp/ansible-tmp-1575982751.31-38290473535447/ > /dev/null 2>&1 && sleep 0'
changed: [localhost] => (item={'value': {u'count': 3}, 'key': u'webserver'}) => {
"ansible_loop_var": "item",
"changed": true,
"instance_ids": [
"i-04b65126b96685ef1",
"i-0b8e340b0b6dfd5d5",
"i-0ee402b469386661c"
],
"instances": [
{
"ami_launch_index": "0",
"architecture": "x86_64",
"block_device_mapping": {
"/dev/sda1": {
"delete_on_termination": true,
"status": "attached",
"volume_id": "vol-07a85b75477bea7cb"
}
},
"dns_name": "ec2-3-120-159-13.eu-central-1.compute.amazonaws.com",
"ebs_optimized": false,
"groups": {
"sg-0a53dff937dec9e1e": "AWS_EC2_tst-sec"
},
"hypervisor": "xen",
"id": "i-04b65126b96685ef1",
"image_id": "ami-0cc0a36f626a4fdf5",
"instance_type": "t2.micro",
"kernel": null,
"key_name": "my_aws",
"launch_time": "2019-12-10T12:59:12.000Z",
"placement": "eu-central-1b",
"private_dns_name": "ip-172-31-32-38.eu-central-1.compute.internal",
"private_ip": "172.31.32.38",
"public_dns_name": "ec2-3-120-159-13.eu-central-1.compute.amazonaws.com",
"public_ip": "3.120.159.13",
"ramdisk": null,
"region": "eu-central-1",
"root_device_name": "/dev/sda1",
"root_device_type": "ebs",
"state": "running",
"state_code": 16,
"tags": {
"Name": "webserver"
},
"tenancy": "default",
"virtualization_type": "hvm"
},
{
"ami_launch_index": "2",
"architecture": "x86_64",
"block_device_mapping": {
"/dev/sda1": {
"delete_on_termination": true,
"status": "attached",
"volume_id": "vol-0f1471bd806709653"
}
},
"dns_name": "ec2-3-120-205-176.eu-central-1.compute.amazonaws.com",
"ebs_optimized": false,
"groups": {
"sg-0a53dff937dec9e1e": "AWS_EC2_tst-sec"
},
"hypervisor": "xen",
"id": "i-0b8e340b0b6dfd5d5",
"image_id": "ami-0cc0a36f626a4fdf5",
"instance_type": "t2.micro",
"kernel": null,
"key_name": "my_aws",
"launch_time": "2019-12-10T12:59:12.000Z",
"placement": "eu-central-1b",
"private_dns_name": "ip-172-31-36-29.eu-central-1.compute.internal",
"private_ip": "172.31.36.29",
"public_dns_name": "ec2-3-120-205-176.eu-central-1.compute.amazonaws.com",
"public_ip": "3.120.205.176",
"ramdisk": null,
"region": "eu-central-1",
"root_device_name": "/dev/sda1",
"root_device_type": "ebs",
"state": "running",
"state_code": 16,
"tags": {
"Name": "webserver"
},
"tenancy": "default",
"virtualization_type": "hvm"
},
{
"ami_launch_index": "1",
"architecture": "x86_64",
"block_device_mapping": {
"/dev/sda1": {
"delete_on_termination": true,
"status": "attached",
"volume_id": "vol-074dc3eb3dfa5cb91"
}
},
"dns_name": "ec2-3-124-186-0.eu-central-1.compute.amazonaws.com",
"ebs_optimized": false,
"groups": {
"sg-0a53dff937dec9e1e": "AWS_EC2_tst-sec"
},
"hypervisor": "xen",
"id": "i-0ee402b469386661c",
"image_id": "ami-0cc0a36f626a4fdf5",
"instance_type": "t2.micro",
"kernel": null,
"key_name": "my_aws",
"launch_time": "2019-12-10T12:59:12.000Z",
"placement": "eu-central-1b",
"private_dns_name": "ip-172-31-47-172.eu-central-1.compute.internal",
"private_ip": "172.31.47.172",
"public_dns_name": "ec2-3-124-186-0.eu-central-1.compute.amazonaws.com",
"public_ip": "3.124.186.0",
"ramdisk": null,
"region": "eu-central-1",
"root_device_name": "/dev/sda1",
"root_device_type": "ebs",
"state": "running",
"state_code": 16,
"tags": {
"Name": "webserver"
},
"tenancy": "default",
"virtualization_type": "hvm"
}
],
"invocation": {
"module_args": {
"assign_public_ip": null,
"aws_access_key": "key",
"aws_secret_key": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"count": 3,
"count_tag": null,
"debug_botocore_endpoint_logs": false,
"ebs_optimized": false,
"ec2_url": null,
"exact_count": null,
"group": null,
"group_id": [
"sg-0a53dff937dec9e1e"
],
"id": "AWS_EC2_tst",
"image": "ami-0cc0a36f626a4fdf5",
"instance_ids": null,
"instance_initiated_shutdown_behavior": "stop",
"instance_profile_name": null,
"instance_tags": {
"Name": "webserver"
},
"instance_type": "t2.micro",
"kernel": null,
"key_name": "my_aws",
"monitoring": false,
"network_interfaces": null,
"placement_group": null,
"private_ip": null,
"profile": null,
"ramdisk": null,
"region": "eu-central-1",
"security_token": null,
"source_dest_check": null,
"spot_launch_group": null,
"spot_price": null,
"spot_type": "one-time",
"spot_wait_timeout": 600,
"state": "present",
"tenancy": "default",
"termination_protection": null,
"user_data": null,
"validate_certs": true,
"volumes": null,
"vpc_subnet_id": null,
"wait": true,
"wait_timeout": 300,
"zone": null
}
},
"item": {
"key": "webserver",
"value": {
"count": 3
}
},
"tagged_instances": []
}
<127.0.0.1> EXEC /bin/sh -c 'echo ~root && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /root/.ansible/tmp/ansible-tmp-1575982784.79-142659143526854 `" && echo ansible-tmp-1575982784.79-142659143526854="` echo /root/.ansible/tmp/ansible-tmp-1575982784.79-142659143526854 `" ) && sleep 0'
Using module file /usr/lib/python2.7/dist-packages/ansible/modules/cloud/amazon/ec2.py
<127.0.0.1> PUT /home/arudy/.ansible/tmp/ansible-local-21511yOIVIE/tmpwFtFnB TO /root/.ansible/tmp/ansible-tmp-1575982784.79-142659143526854/AnsiballZ_ec2.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-tmp-1575982784.79-142659143526854/ /root/.ansible/tmp/ansible-tmp-1575982784.79-142659143526854/AnsiballZ_ec2.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python2 /root/.ansible/tmp/ansible-tmp-1575982784.79-142659143526854/AnsiballZ_ec2.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /root/.ansible/tmp/ansible-tmp-1575982784.79-142659143526854/ > /dev/null 2>&1 && sleep 0'
The full traceback is:
WARNING: The below traceback may *not* be related to the actual failure.
File "/tmp/ansible_ec2_payload_mcI5bP/ansible_ec2_payload.zip/ansible/modules/cloud/amazon/ec2.py", line 1158, in create_instances
File "/usr/local/lib/python2.7/dist-packages/boto/ec2/connection.py", line 977, in run_instances
verb='POST')
File "/usr/local/lib/python2.7/dist-packages/boto/connection.py", line 1208, in get_object
raise self.ResponseError(response.status, response.reason, body)
failed: [localhost] (item={'value': {u'count': 1}, 'key': u'lb'}) => {
"ansible_loop_var": "item",
"changed": false,
"invocation": {
"module_args": {
"assign_public_ip": null,
"aws_access_key": "KEY",
"aws_secret_key": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"count": 1,
"count_tag": null,
"debug_botocore_endpoint_logs": false,
"ebs_optimized": false,
"ec2_url": null,
"exact_count": null,
"group": null,
"group_id": [
"sg-0a53dff937dec9e1e"
],
"id": "AWS_EC2_tst",
"image": "ami-0cc0a36f626a4fdf5",
"instance_ids": null,
"instance_initiated_shutdown_behavior": "stop",
"instance_profile_name": null,
"instance_tags": {
"Name": "lb"
},
"instance_type": "t2.micro",
"kernel": null,
"key_name": "my_aws",
"monitoring": false,
"network_interfaces": null,
"placement_group": null,
"private_ip": null,
"profile": null,
"ramdisk": null,
"region": "eu-central-1",
"security_token": null,
"source_dest_check": null,
"spot_launch_group": null,
"spot_price": null,
"spot_type": "one-time",
"spot_wait_timeout": 600,
"state": "present",
"tenancy": "default",
"termination_protection": null,
"user_data": null,
"validate_certs": true,
"volumes": null,
"vpc_subnet_id": null,
"wait": true,
"wait_timeout": 300,
"zone": null
}
},
"item": {
"key": "lb",
"value": {
"count": 1
}
},
"msg": "Instance creation failed => InvalidParameterValue: Minimum instance count must be greater than zero"
}
解决方案
推荐阅读
- java - spring boot 聚合没有给出预期的结果
- python - 关于 matplotlib.pyplot.matshow 和 np 矩阵对象的一些相关问题:绘制“None”/“nan”和 x 轴偏移
- angular - 如何将焦点设置在角度 6 中的复选框上
- java - 读取文件时如何返回正数和负数
- vue.js - 如何使用 Bootstrap-Vue 从父组件折叠/展开多个动态折叠?
- testing - 如何测试 RTMP 流媒体负载测试
- amazon-web-services - PHP AWS S3 - 使用内容处置下载文件而不使用流式传输
- python - 使用循环创建命名元组的实例作为数据库记录
- cucumber - Citrus cucumber 不提供睡眠的默认实现
- postgresql - 使用 `embeds_many` 查询