2016-12-30 134 views
0

我现在正在使用Ansible 2.1.3.0,并且正试图找出如何使用ec2_ami模块制作实例存储AMI。是否可以使用ec2_ami模块创建实例存储AMI?

它看起来像是不可能做到这一点,如果实例有实例存储根目录 - 无论我做什么,我都得到Instance does not have a volume attached at root (null)"

所以我想知道如何从EBS支持的实例中创建一个intance-store AMI(使用ec2_ami模块)?该文档不允许我将第一卷映射为ami,第二卷需要为ephemeral0。我正想通过ec2_ami模块的源代码,它似乎像它这种不支持,但我可能忽略的东西...

当我在源EC2实例做curl http://169.254.169.254/latest/meta-data/block-device-mapping/,我得到以下几点:

ami 
ephemeral0 

回答

0

我在2.2,并使用ec2而非ec2_ami,但这将完成你在找什么...

- name: Launch instance 
    ec2: 
    aws_access_key: "{{ aws.access_key }}" 
    aws_secret_key: "{{ aws.secret_key }}" 
    instance_tags: "{{ instance.tags }}" 
    count: 1 
    state: started 
    key_name: "{{ instance.key_name }}" 
    group: "{{ instance.security_group }}" 
    instance_type: "{{ instance.type }}" 
    image: "{{ instance.image }}" 
    wait: true 
    region: "{{ aws.region }}" 
    vpc_subnet_id: "{{ subnets_id }}" 
    assign_public_ip: "{{ instance.public_ip }}" 
    instance_profile_name: "{{ aws.iam_role }}" 
    instance_initiated_shutdown_behavior: terminate 
    volumes: 
     - device_name: /dev/sdb 
     volume_type: ephemeral 
     ephemeral: ephemeral0 
    register: ec2 

要特别注意instance_initiated_shutdown_behavior PARAM为DEF ault为stop,与实例存储不兼容,您需要将其设置为terminate才能正常工作。

+0

我知道如何创建这样的EC2实例。然而,问题是要创建一个AMI!我需要做的是在你的任务中创建'instance.image' ... – DejanLekic

+0

@DejanLekic对不起,我误解了,你引用的错误让我失望。我试图做到这一点,我也在这里发布了一个新问题:http://stackoverflow.com/questions/42394774/is-there-an-ansible-module-for-creating-instance-store-based -amis – oucil

+0

@DejanLekic根据这个答案在这里:http://serverfault.com/a/396686/135680我怀疑,因为'ec2_bundle_instance'只是Windows,'ec2_ami'模块可能受到类似的'实例存储'机器,所以这个过程可能需要使用Ansible'命令'任务手动编写脚本。 – oucil

相关问题