From 1e4bd62af5c9669c2a5e54eac6b389d54d4d8410 Mon Sep 17 00:00:00 2001 From: Andrea Mandolo Date: Mon, 1 Dec 2014 17:06:20 +0100 Subject: [PATCH 1/2] Add "block_device_mapping" parameter on EC2_AMI Amazon module - ugraded --- cloud/amazon/ec2_ami.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/cloud/amazon/ec2_ami.py b/cloud/amazon/ec2_ami.py index 98c41357212..23d75171e06 100644 --- a/cloud/amazon/ec2_ami.py +++ b/cloud/amazon/ec2_ami.py @@ -136,6 +136,7 @@ import time try: import boto import boto.ec2 + from boto.ec2.blockdevicemapping import BlockDeviceType, BlockDeviceMapping HAS_BOTO = True except ImportError: HAS_BOTO = False @@ -155,6 +156,7 @@ def create_image(module, ec2): wait_timeout = int(module.params.get('wait_timeout')) description = module.params.get('description') no_reboot = module.params.get('no_reboot') + device_mapping = module.params.get('device_mapping') tags = module.params.get('tags') try: @@ -163,6 +165,17 @@ def create_image(module, ec2): 'description': description, 'no_reboot': no_reboot} + if device_mapping: + bdm = BlockDeviceMapping() + for device in device_mapping: + if 'device_name' not in device: + module.fail_json(msg = 'Device name must be set for volume') + device_name = device['device_name'] + del device['device_name'] + bd = BlockDeviceType(**device) + bdm[device_name] = bd + params['block_device_mapping'] = bdm + image_id = ec2.create_image(**params) except boto.exception.BotoServerError, e: if e.error_code == 'InvalidAMIName.Duplicate': @@ -257,8 +270,8 @@ def main(): description = dict(default=""), no_reboot = dict(default=False, type="bool"), state = dict(default='present'), - tags = dict(type='dict'), - + device_mapping = dict(type='list'), + tags = dict(type='dict') ) ) module = AnsibleModule(argument_spec=argument_spec) @@ -291,4 +304,3 @@ from ansible.module_utils.basic import * from ansible.module_utils.ec2 import * main() - From 0b0d97299868e26134f0c5a240419a1436528cb6 Mon Sep 17 00:00:00 2001 From: Andrea Mandolo Date: Mon, 1 Dec 2014 17:51:48 +0100 Subject: [PATCH 2/2] Add "block_device_mapping" parameter on EC2_AMI Amazon module (DOCUMENTATION) - upgraded --- cloud/amazon/ec2_ami.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/cloud/amazon/ec2_ami.py b/cloud/amazon/ec2_ami.py index 23d75171e06..979dd3b6a25 100644 --- a/cloud/amazon/ec2_ami.py +++ b/cloud/amazon/ec2_ami.py @@ -69,6 +69,12 @@ options: - Image ID to be deregistered. required: false default: null + device_mapping: + version_added: "1.9" + description: + - An optional list of devices with custom configurations (same block-device-mapping parameters) + required: false + default: null delete_snapshot: description: - Whether or not to delete an AMI while deregistering it. @@ -110,6 +116,23 @@ EXAMPLES = ''' name: newtest register: instance +# AMI Creation, with a custom root-device size and another EBS attached +- ec2_ami + aws_access_key: xxxxxxxxxxxxxxxxxxxxxxx + aws_secret_key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + instance_id: i-xxxxxx + name: newtest + device_mapping: + - device_name: /dev/sda1 + size: XXX + delete_on_termination: true + volume_type: gp2 + - device_name: /dev/sdb + size: YYY + delete_on_termination: false + volume_type: gp2 + register: instance + # Deregister/Delete AMI - ec2_ami: aws_access_key: xxxxxxxxxxxxxxxxxxxxxxx