-
Notifications
You must be signed in to change notification settings - Fork 342
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ec2_instance_info - add support for include_attributes (#1577)
ec2_instance_info - add support for include_attributes SUMMARY include_attributes allows the module to describe specific attributes for an EC2 instance ISSUE TYPE Feature Pull Request COMPONENT NAME ec2_instance_info Reviewed-by: Alina Buzachis Reviewed-by: Bikouo Aubin Reviewed-by: Helen Bailey <[email protected]>
- Loading branch information
Showing
6 changed files
with
173 additions
and
0 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
changelogs/fragments/ec2_instance_info-support-new-attribute.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
minor_changes: | ||
- ec2_instance_info - add new parameter `include_attributes` to describe instance attributes (https://github.com/ansible-collections/amazon.aws/pull/1577). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
time=1m | ||
cloud/aws | ||
ec2_instance_info | ||
ec2_instance |
7 changes: 7 additions & 0 deletions
7
tests/integration/targets/ec2_instance_info/defaults/main.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
ec2_instance_type: 't2.micro' | ||
ec2_instance_tag_TestId: '{{ resource_prefix }}-instance-info' | ||
ec2_instance_name: "{{ resource_prefix }}-test-instance-info" | ||
ec2_instance_user_data: | | ||
packages: | ||
- httpd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# this just makes sure they're in the right place | ||
dependencies: | ||
- role: setup_ec2_facts | ||
- role: setup_ec2_instance_env |
76 changes: 76 additions & 0 deletions
76
tests/integration/targets/ec2_instance_info/tasks/main.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
--- | ||
- module_defaults: | ||
group/aws: | ||
aws_access_key: "{{ aws_access_key }}" | ||
aws_secret_key: "{{ aws_secret_key }}" | ||
security_token: "{{ security_token | default(omit) }}" | ||
region: "{{ aws_region }}" | ||
block: | ||
- name: "Make instance in the testing subnet created in the test VPC" | ||
ec2_instance: | ||
state: present | ||
name: "{{ ec2_instance_name }}" | ||
image_id: "{{ ec2_ami_id }}" | ||
availability_zone: '{{ subnet_b_az }}' | ||
tags: | ||
TestId: "{{ ec2_instance_tag_TestId }}" | ||
user_data: "{{ ec2_instance_user_data }}" | ||
instance_type: "{{ ec2_instance_type }}" | ||
wait: false | ||
|
||
- name: "Gather {{ ec2_instance_name }} info" | ||
ec2_instance_info: | ||
filters: | ||
"tag:Name": "{{ ec2_instance_name }}" | ||
include_attributes: | ||
- instanceType | ||
- kernel | ||
- ramdisk | ||
- userData | ||
- disableApiTermination | ||
- instanceInitiatedShutdownBehavior | ||
- rootDeviceName | ||
- blockDeviceMapping | ||
- productCodes | ||
- sourceDestCheck | ||
- groupSet | ||
- ebsOptimized | ||
- sriovNetSupport | ||
- enclaveOptions | ||
register: _instance_info | ||
|
||
- name: Validate that returned value contains required attributes | ||
assert: | ||
that: | ||
- _instance_info.instances | length > 0 | ||
- '"attributes" in _instance_info.instances[0]' | ||
# instance type | ||
- _instance_info.instances[0].attributes.instance_type.value == ec2_instance_type | ||
# User data | ||
- _instance_info.instances[0].attributes.user_data.value | b64decode == ec2_instance_user_data | ||
# kernel | ||
- '"kernel_id" in _instance_info.instances[0].attributes' | ||
# Ram disk | ||
- '"ramdisk_id" in _instance_info.instances[0].attributes' | ||
# Disable API termination | ||
- not (_instance_info.instances[0].attributes.disable_api_termination.value | bool) | ||
# Instance Initiated Shutdown Behavior | ||
- '"instance_initiated_shutdown_behavior" in _instance_info.instances[0].attributes' | ||
# Root Device Name | ||
- _instance_info.instances[0].attributes.root_device_name.value == "/dev/sda1" | ||
# Block Device Mapping | ||
- '"block_device_mappings" in _instance_info.instances[0].attributes' | ||
- _instance_info.instances[0].attributes.block_device_mappings[0].device_name == "/dev/sda1" | ||
- '"ebs" in _instance_info.instances[0].attributes.block_device_mappings[0]' | ||
# Product Codes | ||
- '"product_codes" in _instance_info.instances[0].attributes' | ||
# Source Dest Check | ||
- _instance_info.instances[0].attributes.source_dest_check.value | bool | ||
# GroupSet | ||
- '"groups" in _instance_info.instances[0].attributes' | ||
# Ebs Optimized | ||
- not (_instance_info.instances[0].attributes.ebs_optimized.value | bool) | ||
# Sriov Net Support | ||
- '"sriov_net_support" in _instance_info.instances[0].attributes' | ||
# Enclave Options | ||
- not (_instance_info.instances[0].attributes.enclave_options.enabled | bool) |