amazon-web-services - 使用 Ansible 创建 Aws ec2 实例时出错
问题描述
我已经运行了简单的任务来创建 aws 实例。
之后创建了实例,我从 AWS Web 控制台终止了 ec2 实例。后来我向它添加了更多任务,但永远无法使用这些任务创建 ec2 实例。
我不断收到错误消息:
致命的:[本地主机]:失败!=> {"changed": false, "msg": "id(s) ['i-0f513aec91787e83d'] 的实例之前已创建但已被终止 - 使用(可能不同的)'instance-id' 参数"}
它不断报告先前的实例 ID。我可以看到我的 AWS 控制台中没有这样的实例。
有人可以向我解释为什么会这样吗?
- name: get any running ec2 instance
ec2_instance_info:
aws_access_key: "{{ec2_access_key}}"
aws_secret_key: "{{ec2_secret_key}}"
region: "{{region}}"
filters:
instance-state-name: ['running']
register: ec2_list
- name: Display ec2_list
debug: msg="{{item.instance_id}}"
with_items: "{{ec2_list.instances}}"
- name: Terminate Any running Instances
ec2:
state: 'absent'
instance_ids: "{item.instance_id}"
with_items: "{{ec2_list.instances}}"
- name: Create new ec-2 instance
ec2:
aws_access_key: "{{ec2_access_key}}"
aws_secret_key: "{{ec2_secret_key}}"
key_name: "{{key_name}}"
id: "{{id}}"
instance_type: t2.micro
image: "{{image}}"
region: "{{region}}"
vpc_subnet_id: "{{vpc_subnet_id}}"
wait: yes
count: 1
assign_public_ip: yes
register: ec2
- name: Wait for ssh to come up
delegate_to: "{{ item.public_dns_name }}"
wait_for_connection:
delay: 60
timeout: 320
loop: "{{ ec2.instances }}"
- name: Terminate currently running Instances
ec2:
state: 'absent'
instance_ids: "{{ec2.instance_ids}}"
解决方案
ec2 ansible 模块的文档说:
id:此标识符在实例终止后至少 24 小时内有效,以后不应再用于其他调用。
你改变了这个id吗?
推荐阅读
- maven - 提供的范围版本如何在 mavan 中工作
- android - 防止在 android 应用中使用以前的帐户自动 google 登录
- python-3.x - 关闭终端后在 cpanel 终端中运行 python 文件
- javascript - (PHP) 如何从下拉列表中获取值并将变量用作 html 链接的一部分
- excel - vba 选择特定的工作表并将创建的每个 PDF 保存/导出到不同的文件夹
- python - 估计偏度系数
- c++ - 具有参数和数组输入的构造函数不起作用c ++
- r - 基于阈值标记气泡图
- node.js - socket.io:cookie 未在初始连接时发送
- javascript - 如何在 MDBootstrap 中为 DataTables 使用异步 .update() 方法?