Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Backport) ec2_instance, ebs_optimized not sub-option of network #48467

Merged
merged 3 commits into from
Nov 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/BOTMETA.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ files:
$modules/cloud/amazon/ec2_asg.py: $team_ansible s-hertel ryansb
$modules/cloud/amazon/ec2_group.py: $team_ansible
$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_key.py: $team_ansible
$modules/cloud/amazon/ec2_lc.py: $team_ansible
Expand Down
2 changes: 2 additions & 0 deletions changelogs/fragments/48341-ebs-optimized-ec2-instance.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- "ec2_instance: - Fixed issue where ebs_optimized was considered sub-option of the network parameter. (https://github.com/ansible/ansible/issues/48159)"
10 changes: 8 additions & 2 deletions lib/ansible/modules/cloud/amazon/ec2_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -1054,7 +1054,10 @@ def build_top_level_options(params):
spec['CreditSpecification'] = {'CpuCredits': params.get('cpu_credit_specification')}
if params.get('tenancy') is not None:
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')
if params.get('instance_initiated_shutdown_behavior'):
spec['InstanceInitiatedShutdownBehavior'] = params.get('instance_initiated_shutdown_behavior')
Expand Down Expand Up @@ -1516,6 +1519,9 @@ def main():
)

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('security_group'):
module.fail_json(msg="Parameter network.interfaces can't be used with security_group")
Expand Down Expand Up @@ -1565,7 +1571,7 @@ def main():
module.params['filters'] = filters

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'))
changed = False
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,19 @@ ec2_ami_image:
us-east-2: ami-9cbf9bf9
us-west-1: ami-7c280d1c
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
Original file line number Diff line number Diff line change
@@ -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 }}"
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@
- include_tasks: block_devices.yml
- include_tasks: default_vpc_tests.yml
- include_tasks: iam_instance_role.yml
- include_tasks: checkmode_tests.yml
- include_tasks: ebs_optimized.yml


# ============================================================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
security_token: "{{ security_token }}"
region: "{{ aws_region }}"
no_log: True

- name: Include vars file in roles/ec2_instance/defaults/main.yml
include_vars:
file: 'roles/ec2_instance/defaults/main.yml'
Expand All @@ -31,8 +31,8 @@
register: ec2_instance_cpu_options_creation
ignore_errors: yes

- name: check that graceful error message is returned when creation with cpu_options and old botocore
- name: check that graceful error message is returned when creation with cpu_options and old botocore
assert:
that:
- ec2_instance_cpu_options_creation.failed
- 'ec2_instance_cpu_options_creation.msg == "cpu_options is only supported with botocore >= 1.10.16"'
- 'ec2_instance_cpu_options_creation.msg == "cpu_options is only supported with botocore >= 1.10.16"'