gpt4 book ai didi

amazon-web-services - 尝试使用 ansible 更改 EC2 实例的根 volume_size 时出错

转载 作者:行者123 更新时间:2023-12-04 08:12:18 24 4
gpt4 key购买 nike

我正在尝试使用 ansible playbook 创建一个 EC2 实例,并使用该 playbook 设置根卷大小。当然,如果不包含volumes变量,效果很好。但是,我想为根卷设置不同的默认大小。

我的剧本如下所示:

# Use the ec2 module to create a new host and then add
# it to a special "ec2hosts" group.

- hosts: localhost
connection: local
gather_facts: False
vars:
instance_type: "t2.micro"
image: "ami-1420b57c"
region: "us-east-1"
volumes:
- device_name: /dev/xvda
volume_size: 10

tasks:
- name: make one instance
ec2: image="{{ image }}"
instance_type="{{ instance_type }}"
keypair="{{ keypair }}"
region="{{ region }}"
group="{{ group }}"
volumes="{{ volumes }}"
instance_tags='{"Name":"{{instance_name}}"}'
wait=true
register: ec2_host

- debug: var=ec2_host
- debug: var=item
with_items: ec2_host.instance_ids

- add_host: hostname={{ item.public_ip }} groupname=ec2hosts
with_items: ec2_host.instances

然后当我运行 playbook 命令时,出现以下错误。
ansible-playbook ec2-simple.yml -e "instance_name=testnode keypair=mykeypair group=testgroup"

PLAY [localhost] **************************************************************

TASK: [make one instance] *****************************************************
failed: [localhost] => {"failed": true}
msg: Device name must be set for volume

FATAL: all hosts have already failed -- aborting

我已经尝试过替代方案。有无引号等,没有任何效果。有时,我会遇到不同的错误。

我在 Mac 上使用 Ansible 1.7.2。

最佳答案

我有兴趣回答这个问题,因为您提供了一个(几乎)完全有效的示例。我在本地复制了它,对我的 AWS 账户进行了一些小改动,然后反复找出解决方案。

我怀疑是 YAML+Ansible 问题。我尝试了很多东西并环顾四周。 Michael DeHaan(Ansible 的创建者)said the complex argument/module style is required as seen in the ec2 examples .这是模块现在的样子——其他地方没有变化。

  tasks:
- name: make one instance
local_action:
module: ec2
image: "{{ image }}"
instance_type: "{{ instance_type }}"
keypair: "{{ keypair }}"
region: "{{ region }}"
group: "{{ group }}"
volumes: "{{volumes}}"
instance_tags: '{"Name":"{{instance_name}}"}'
wait: true
register: ec2_host

转换后它起作用了——或者至少出现了下一个错误,这是因为 EC2 实例需要在 VPC 中(下面的错误)。我希望你能解决这个问题 - 如果没有,请发表评论,我会让它充分发挥作用。
TASK: [make one instance] ***************************************************** 
<127.0.0.1> REMOTE_MODULE ec2 region=us-east-1 keypair=mykey instance_type=t2.micro image=ami-1420b57c group=default
failed: [127.0.0.1 -> 127.0.0.1] => {"failed": true}
msg: Instance creation failed => VPCResourceNotSpecified: The specified instance type can only be used in a VPC. A subnet ID or network interface ID is required to carry out the request.

关于amazon-web-services - 尝试使用 ansible 更改 EC2 实例的根 volume_size 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27074852/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com