ec2_instance: ebs_optimized is not sub-option of 'network' (#48341)

* ebs_optimized is not suboption of 'network'

* Add Shaps as ec2_instance maintainer

* Added workaround-backward compatible check for ebs_optimized

* Added ebs_optimized test

* CI fixes, dynamic select of ENA-enabled AMI
pull/48419/head
Andrea Tartaglia 6 years ago committed by John R Barker
parent 3147dc2a15
commit b7d9feb7dc

@ -53,6 +53,7 @@ files:
$modules/cloud/amazon/ec2_asg.py: $team_ansible s-hertel ryansb $modules/cloud/amazon/ec2_asg.py: $team_ansible s-hertel ryansb
$modules/cloud/amazon/ec2_group.py: $team_ansible $modules/cloud/amazon/ec2_group.py: $team_ansible
$modules/cloud/amazon/ec2_group_facts.py: willthames $modules/cloud/amazon/ec2_group_facts.py: willthames
$modules/cloud/amazon/ec2_instance.py: Shaps
$modules/cloud/amazon/ec2_instance_facts.py: willthames $modules/cloud/amazon/ec2_instance_facts.py: willthames
$modules/cloud/amazon/ec2_key.py: $team_ansible $modules/cloud/amazon/ec2_key.py: $team_ansible
$modules/cloud/amazon/ec2_lc.py: $team_ansible $modules/cloud/amazon/ec2_lc.py: $team_ansible

@ -1111,7 +1111,10 @@ def build_top_level_options(params):
spec['CreditSpecification'] = {'CpuCredits': params.get('cpu_credit_specification')} spec['CreditSpecification'] = {'CpuCredits': params.get('cpu_credit_specification')}
if params.get('tenancy') is not None: if params.get('tenancy') is not None:
spec['Placement'] = {'Tenancy': params.get('tenancy')} spec['Placement'] = {'Tenancy': params.get('tenancy')}
if (params.get('network') or {}).get('ebs_optimized') is not None: if params.get('ebs_optimized') is not None:
spec['EbsOptimized'] = params.get('ebs_optimized')
elif (params.get('network') or {}).get('ebs_optimized') is not None:
# Backward compatibility for workaround described in https://github.com/ansible/ansible/issues/48159
spec['EbsOptimized'] = params['network'].get('ebs_optimized') spec['EbsOptimized'] = params['network'].get('ebs_optimized')
if params.get('instance_initiated_shutdown_behavior'): if params.get('instance_initiated_shutdown_behavior'):
spec['InstanceInitiatedShutdownBehavior'] = params.get('instance_initiated_shutdown_behavior') spec['InstanceInitiatedShutdownBehavior'] = params.get('instance_initiated_shutdown_behavior')
@ -1597,6 +1600,9 @@ def main():
) )
if module.params.get('network'): if module.params.get('network'):
if 'ebs_optimized' in module.params['network']:
module.deprecate("network.ebs_optimized is deprecated."
"Use the top level ebs_optimized parameter instead", 2.9)
if module.params.get('network').get('interfaces'): if module.params.get('network').get('interfaces'):
if module.params.get('security_group'): if module.params.get('security_group'):
module.fail_json(msg="Parameter network.interfaces can't be used with security_group") module.fail_json(msg="Parameter network.interfaces can't be used with security_group")
@ -1646,7 +1652,7 @@ def main():
module.params['filters'] = filters module.params['filters'] = filters
if module.params.get('cpu_options') and not module.botocore_at_least('1.10.16'): if module.params.get('cpu_options') and not module.botocore_at_least('1.10.16'):
module.fail_json(msg="cpu_options is only supported with botocore >= 1.10.16") module.fail_json(msg="cpu_options is only supported with botocore >= 1.10.16")
existing_matches = find_instances(ec2, filters=module.params.get('filters')) existing_matches = find_instances(ec2, filters=module.params.get('filters'))
changed = False changed = False

@ -18,3 +18,19 @@ ec2_ami_image:
us-east-2: ami-9cbf9bf9 us-east-2: ami-9cbf9bf9
us-west-1: ami-7c280d1c us-west-1: ami-7c280d1c
us-west-2: ami-0c2aba6c us-west-2: ami-0c2aba6c
# We need to use ENA enabled AMIs to get EBS optimized instances.
ec2_ebs_optimized_ami_image:
ap-northeast-1: ami-00f9d04b3b3092052
ap-northeast-2: ami-0c764df09c35858b8
ap-south-1: ami-00796998f258969fd
ap-southeast-1: ami-085fd1bd447be68e8
ap-southeast-2: ami-0b8dea0e70b969adc
ca-central-1: ami-05cac140c6a1fb960
eu-central-1: ami-02ea8f348fa28c108
eu-west-1: ami-0a5e707736615003c
eu-west-2: ami-017b0e29fac27906b
sa-east-1: ami-0160a8b6087883cb6
us-east-1: ami-013be31976ca2c322
us-east-2: ami-0350c5670171b5391
us-west-1: ami-01beb64058d271bc4
us-west-2: ami-061e7ebbc234015fe

@ -0,0 +1,34 @@
- name: set connection information for all tasks
set_fact:
aws_connection_info: &aws_connection_info
aws_access_key: "{{ aws_access_key }}"
aws_secret_key: "{{ aws_secret_key }}"
security_token: "{{ security_token }}"
region: "{{ aws_region }}"
no_log: true
- name: Make EBS optimized instance in the testing subnet of the test VPC
ec2_instance:
name: "{{ resource_prefix }}-test-ebs-optimized-instance-in-vpc"
image_id: "{{ ec2_ebs_optimized_ami_image[aws_region] }}"
tags:
TestId: "{{ resource_prefix }}"
security_groups: "{{ sg.group_id }}"
vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}"
ebs_optimized: true
instance_type: t3.nano
<<: *aws_connection_info
register: ebs_opt_in_vpc
- name: Get ec2 instance facts
ec2_instance_facts:
filters:
"tag:Name": "{{ resource_prefix }}-test-ebs-optimized-instance-in-vpc"
"instance-state-name": "running"
<<: *aws_connection_info
register: ebs_opt_instance_fact
- name: Assert instance is ebs_optimized
assert:
that:
- "{{ ebs_opt_instance_fact.instances.0.ebs_optimized }}"

@ -97,6 +97,7 @@
- include_tasks: default_vpc_tests.yml - include_tasks: default_vpc_tests.yml
- include_tasks: iam_instance_role.yml - include_tasks: iam_instance_role.yml
- include_tasks: checkmode_tests.yml - include_tasks: checkmode_tests.yml
- include_tasks: ebs_optimized.yml
# ============================================================ # ============================================================

Loading…
Cancel
Save