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

标签 amazon-web-services amazon-ec2 ansible ansible-playbook

我正在尝试使用 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/

相关文章:

ansible - 使用 Ansible 中的authorized_key模块将多个公共(public)ssh key 分配给用户定义

javascript - 无法在 AWS Lambda 函数上使用 ES6;如何在 Lambda 中导入 ES6 模块

database - 为分析选择合适的数据库的困难

amazon-web-services - 如何将 SSL 证书从证书颁发机构复制到 EC2?

python - 聚合时间序列数据

amazon-web-services - 如何将预先存在的 key SSH 添加到 ansible? (加密)

ansible - 使用依赖角色配置 Ansible 角色

amazon-web-services - 亚马逊雅典娜 : How to store results after querying with skipping column headers?

node.js - 如何使用 "node-ses"发送原始电子邮件而不提供访问 key 和 secret key ?或使用 IAM 角色

java - 亚马逊 SWF @Signal