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

ec2_instance module will not return state when state OK (already exists) #859

Closed
1 task done
IPvSean opened this issue Jun 2, 2022 · 4 comments
Closed
1 task done
Labels
bug This issue/PR relates to a bug module module needs_triage plugins plugin (any type) python3

Comments

@IPvSean
Copy link
Contributor

IPvSean commented Jun 2, 2022

Summary

In provisioning I am noticing that if I do

-> ec2_instance
-> do something like ec2_tag over the results of ec2_instance

it will work the first time... but ec2_instance will not return instances when it is OK, so subsequent runs will fail

However this will work everytime->

-> ec2_instance
-> ec2_instance_info
-> ec2_tag

This behavior seems wrong to me... it differs from the older ec2 module and forces the playbook author to create an additional task to do something that the ec2_instance should do by itself

Issue Type

Bug Report

Component Name

ec2_instance

Ansible Version

$ ansible --version

Collection Versions

$ ansible-galaxy collection list
➜  provisioner git:(gh-pages) ✗ ansible-galaxy collection list

# /Users/sean/.ansible/collections/ansible_collections
Collection                          Version
----------------------------------- -------
amazon.aws                          3.2.0
ansible.netcommon                   2.0.2
ansible.network                     1.2.0
ansible.posix                       1.3.0
ansible.product_demos               1.2.12
ansible.utils                       2.6.0
ansible.windows                     1.5.0
ansible.workshops                   1.0.11
arista.eos                          2.1.2
awx.awx                             19.2.2
azure.azcollection                  1.12.0
chocolatey.chocolatey               1.1.0
cisco.ios                           2.0.1
cisco.iosxr                         2.8.1
cisco.nxos                          2.9.0
community.aws                       3.2.1
community.crypto                    1.6.2
community.general                   3.0.2
community.mysql                     2.1.0
community.windows                   1.3.0
containers.podman                   1.9.3
f5networks.f5_modules               1.9.0
frr.frr                             1.0.3
junipernetworks.junos               2.1.0
openvswitch.openvswitch             2.1.0
redhat_cop.controller_configuration 2.0.0
redhat_cop.tower_utilities          0.3.2
vyos.vyos                           2.8.0

AWS SDK versions

$ pip show boto boto3 botocore
Name: boto
Version: 2.49.0
Summary: Amazon Web Services Library
Home-page: https://github.com/boto/boto/
Author: Mitch Garnaat
Author-email: [email protected]
License: MIT
Location: /usr/local/lib/python3.9/site-packages
Requires:
Required-by:
---
Name: boto3
Version: 1.20.51
Summary: The AWS SDK for Python
Home-page: https://github.com/boto/boto3
Author: Amazon Web Services
Author-email:
License: Apache License 2.0
Location: /usr/local/lib/python3.9/site-packages
Requires: botocore, jmespath, s3transfer
Required-by:
---
Name: botocore
Version: 1.23.51
Summary: Low-level, data-driven core of boto 3.
Home-page: https://github.com/boto/botocore
Author: Amazon Web Services
Author-email:
License: Apache License 2.0
Location: /usr/local/lib/python3.9/site-packages
Requires: jmespath, python-dateutil, urllib3
Required-by: boto3, s3transfer

Configuration

$ ansible-config dump --only-changed
DEFAULT_FORKS(/Users/sean/Documents/GitHub/IPvSean/workshops/provisioner/ansible.cfg) = 50
DEFAULT_HOST_LIST(/Users/sean/Documents/GitHub/IPvSean/workshops/provisioner/ansible.cfg) = ['/Users/sean/Documents/GitHub/IPvSean/workshops/provisioner/hosts']
DEFAULT_STDOUT_CALLBACK(/Users/sean/Documents/GitHub/IPvSean/workshops/provisioner/ansible.cfg) = yaml
HOST_KEY_CHECKING(/Users/sean/Documents/GitHub/IPvSean/workshops/provisioner/ansible.cfg) = False
PERSISTENT_COMMAND_TIMEOUT(/Users/sean/Documents/GitHub/IPvSean/workshops/provisioner/ansible.cfg) = 60
PERSISTENT_CONNECT_TIMEOUT(/Users/sean/Documents/GitHub/IPvSean/workshops/provisioner/ansible.cfg) = 60
RETRY_FILES_ENABLED(/Users/sean/Documents/GitHub/IPvSean/workshops/provisioner/ansible.cfg) = False

OS / Environment

Mac OS 12.4 Monterey

Steps to Reproduce

- name: Create EC2 instances for qradar
  amazon.aws.ec2_instance:
    key_name: "{{ ec2_name_prefix }}-key"
    security_group: "{{ ec2_security_group }}"
    instance_type: "{{ ec2_info['qradar']['size'] }}"
    image_id: "{{ qradar_ami['image_id'] }}"
    region: "{{ ec2_region }}"
    exact_count: "{{ student_total }}"
    state: running
    filters:
      "tag:Workshop_qradar": "{{ ec2_name_prefix }}-qradar"
      instance-state-name: running
    tags:
      Workshop_qradar: "{{ ec2_name_prefix }}-qradar"
      Workshop: "{{ ec2_name_prefix }}"
      Workshop_type: "{{ workshop_type }}"
      AWS_USERNAME: "{{ aws_user }}"
      owner: "{{ aws_user }}"
      Info: "AWS_USERNAME that provisioned this-> {{ aws_user }}"
      Ansible_Workshops: "This was provisioned through the ansible workshops provisioner"
      Students: "{{ student_total }}"
      username: '{{ ec2_info["rhel8"]["username"] }}'
      short_name: "qradar"
      ansible-workshops: "true"
    wait: "{{ ec2_wait }}"
    network:
      assign_public_ip: true
    vpc_subnet_id: "{{ ec2_vpc_subnet_id }}"
    volumes:
      - device_name: /dev/sda1
        ebs:
          volume_type: "{{ ec2_info['qradar']['disk_volume_type'] }}"
          volume_size: "{{ ec2_info['qradar']['disk_space'] }}"
          iops: "{{ ec2_info['qradar']['disk_iops'] }}"
          throughput: "{{ ec2_info['qradar']['disk_throughput'] }}"
          delete_on_termination: true
  when: security_console == 'qradar'
  async: "{{ async_timeout_seconds }}"
  poll: 0
  register: qradar_async

- name: Ensure tags are present for qradar
  amazon.aws.ec2_tag:
    region: "{{ ec2_region }}"
    resource: "{{ item[1]['instance_id'] }}"
    state: present
    tags:
      Name: "{{ ec2_name_prefix }}-student{{ item[0] + 1 }}-qradar"
      Index: "{{ item[0] }}"
      Student: "student{{ item[0] + 1 }}"
      launch_time: "{{ item.1.launch_time }}"
      ansible-workshops: "true"
  with_indexed_items:
    - "{{ siem_output.instances }}"
  async: "{{ async_timeout_seconds }}"
  poll: 0
  register: ensure_tags_qradar_async
  when:
    - (security_console == 'qradar') and (siem_output['instance_ids'] is not none)

Expected Results

I would expect idempotency to work every-time without my own logic with the ec2_instance_info

Actual Results

TASK [../roles/manage_ec2_instances : Wait for async instance creation to complete] ********************************************************************************
ok: [localhost] => (item={'started': 1, 'finished': 0, 'ansible_job_id': '69946880772.8308', 'results_file': '/tmp/.ansible_async/69946880772.8308', 'changed': True, 'failed': False})
ok: [localhost] => (item={'started': 1, 'finished': 0, 'ansible_job_id': '430878465557.8333', 'results_file': '/tmp/.ansible_async/430878465557.8333', 'changed': True, 'failed': False})
ok: [localhost] => (item={'started': 1, 'finished': 0, 'ansible_job_id': '888423871718.8355', 'results_file': '/tmp/.ansible_async/888423871718.8355', 'changed': True, 'failed': False})
ok: [localhost] => (item={'started': 1, 'finished': 0, 'ansible_job_id': '675347621767.8377', 'results_file': '/tmp/.ansible_async/675347621767.8377', 'changed': True, 'failed': False})
ok: [localhost] => (item={'started': 1, 'finished': 0, 'ansible_job_id': '833453438550.8399', 'results_file': '/tmp/.ansible_async/833453438550.8399', 'changed': True, 'failed': False})

TASK [../roles/manage_ec2_instances : set_fact] ********************************************************************************************************************
ok: [localhost]

TASK [../roles/manage_ec2_instances : Ensure tags are present for splunk] ******************************************************************************************
skipping: [localhost]

TASK [../roles/manage_ec2_instances : Ensure tags are present for qradar] ******************************************************************************************
fatal: [localhost]: FAILED! =>
  msg: '''dict object'' has no attribute ''instances'''

TASK [../roles/manage_ec2_instances : Ensure tags are present for splunk] ******************************************************************************************
skipping: [localhost]

TASK [../roles/manage_ec2_instances : Ensure tags are present for qradar] ******************************************************************************************
fatal: [localhost]: FAILED! =>
  msg: '''dict object'' has no attribute ''instances'''

Code of Conduct

  • I agree to follow the Ansible Code of Conduct
@ansibullbot
Copy link

Files identified in the description:

If these files are inaccurate, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibullbot
Copy link

@ansibullbot ansibullbot added bug This issue/PR relates to a bug module module needs_triage plugins plugin (any type) python3 labels Jun 2, 2022
@abenokraitis
Copy link

👀

@jillr
Copy link
Contributor

jillr commented Jun 28, 2022

@IPvSean if I understand correctly, the scenario is that you run the playbook once to create the instances and everything works properly. If you run the playbook a second time, the ec2_instance task sees that the instances already exist so it does not act. Generally, CUD modules do not perform list or describe operations so no information about the instances is returned. Then, the ec2_tag task fails because '{{ siem_output }}' doesn't have any instance info. You have to add an ec2_instance_info task to perform a list action.

This is how the (amazon|community).aws are developed. Adding an ec2_instance_info task is the expected way to solve this.

@jillr jillr closed this as completed Jun 28, 2022
softwarefactory-project-zuul bot pushed a commit that referenced this issue Feb 24, 2023
fix incomplete enforce_count() return values

SUMMARY

This is the Ansible way.
Since a call to enforce_count() requires that a call to find_instances() has already been made, the information required to populate the instances return key is already held by the variable existing_matches. There are zero use cases where it makes sense not to output this information; if I want exactly one such instance and an existing instance matches the filter, I definitely always want to know its details.

Fixes #963, #859
ISSUE TYPE


Bugfix Pull Request

COMPONENT NAME

ec2_instance
ADDITIONAL INFORMATION


See linked issues.

Before:
{                                                                                                                                                                                                                                                                                                                                                                          
    "changed": false,                                                                                                                                                                                                                                                                                                                                                                         
    "invocation": {                                                                                                                                                                                                                                                                                                                                                                           
        "module_args": {                                                                                                                                                                                                                                                                                                                                                                      
            "availability_zone": null,                                                                                                                                                                                                                                                                                                                                                        
            "aws_access_key": null,                                                                                                                                                                                                                                                                                                                                                           
            "aws_ca_bundle": null,                                                                                                                                                                                                                                                                                                                                                            
            "aws_config": null,                                                                                                                                                                                                                                                                                                                                                               
            "aws_secret_key": null,                                                                                                                                                                                                                                                                                                                                                           
            "count": null,                                                                                                                                                                                                                                                                                                                                                                    
            "cpu_credit_specification": null,                                                                                                                                                                                                                                                                                                                                                 
            "cpu_options": null,                                                                                                                                                                                                                                                                                                                                                              
            "debug_botocore_endpoint_logs": false,                                                                                                                                                                                                                                                                                                                                            
            "detailed_monitoring": false,                                                                                                                                                                                                                                                                                                                                                     
            "ebs_optimized": true,                                                                                                                                                                                                                                                                                                                                                            
            "ec2_url": null,                                                                                                                                                                                                                                                                                                                                                                  
            "exact_count": 1,                                                                                                                                                                                                                                                                                                                                                                 
            "filters": {                                                                                                                                                                                                                                                                                                                                                                      
                "tag:Name": "something",                                                                                                                                                                                                                                                                                                                                             
                "tag:env": "prod"                                                                                                                                                                                                                                                                                                                                                             
            },
            "image": null,                                                                                                                                                                                                                                                                                                                                                                    
            "image_id": "REDACTED",                                                                                                                                                                                                                                                                                                                                              
            "instance_ids": [],                                                                                                                                                                                                                                                                                                                                                               
            "instance_initiated_shutdown_behavior": null,                                                                                                                                                                                                                                                                                                                                     
            "instance_role": "REDACTED",                                                                                                                                                                                                                                                                                                                                                       
            "instance_type": "m5.2xlarge",                                                                                                                                                                                                                                                                                                                                                    
            "key_name": "REDACTED",                                                                                                                                                                                                                                                                                                                                                          
            "launch_template": null,                                                                                                                                                                                                                                                                                                                                                          
            "metadata_options": null,                                                                                                                                                                                                                                                                                                                                                         
            "name": null,                                                                                                                                                                                                                                                                                                                                                                     
            "network": {                                                                                                                                                                                                                                                                                                                                                                      
                "source_dest_check": true                                                                                                                                                                                                                                                                                                                                                     
            },                                                                                                                                                                                                                                                                                                                                                                                
            "placement_group": null,                                                                                                                                                                                                                                                                                                                                                          
            "profile": null,                                                                                                                                                                                                                                                                                                                                                                  
            "purge_tags": false,                                                                                                                                                                                                                                                                                                                                                              
            "region": "us-west-2",                                                                                                                                                                                                                                                                                                                                                            
            "security_group": null,                                                                                                                                                                                                                                                                                                                                                           
            "security_groups": [                                                                                                                                                                                                                                                                                                                                                              
                "default"                                                                                                                                                                                                                                                                                                                                                                     
            ],                                                                                                                                                                                                                                                                                                                                                                                
            "security_token": null,                                                                                                                                                                                                                                                                                                                                                           
            "state": "present",                                                                                                                                                                
            "tags": {                                                                                                                                                                                                                                                                                                                                                                         
                "Name": "something",                                                                                                                                                                                                                                                                                                                                                         
                "env": "prod",
            },
            "tenancy": null,
            "termination_protection": null,
            "tower_callback": null,
            "user_data": "REDACTED",
            "validate_certs": true,
            "volumes": [
                {
                    "device_name": "/dev/sda1",
                    "ebs": {
                        "delete_on_termination": true,
                        "encrypted": true,
                        "volume_size": 20,
                        "volume_type": "gp3"
                    }
                },
                {
                    "device_name": "/dev/xvdo",
                    "ebs": {
                        "delete_on_termination": true,
                        "encrypted": true,
                        "volume_size": 20,
                        "volume_type": "gp3"
                    }
                },
                {
                    "device_name": "/dev/xvdp",
                    "ebs": {
                        "delete_on_termination": true,
                        "encrypted": true,
                        "volume_size": 10,
                        "volume_type": "gp3"
                    }
                },
                {
                    "device_name": "/dev/xvdi",
                    "ebs": {
                        "delete_on_termination": true,
                        "encrypted": true,
                        "volume_size": 100,
                        "volume_type": "gp3"
                    }
                }
            ],
            "vpc_subnet_id": "REDACTED",
            "wait": true,
            "wait_timeout": 300
        }
    },
    "msg": "1 instances already running, nothing to do."
}
After:
{                                                                                                                                                                                                                                                                                                                                                                          
    "changed": false,                                                                                                                                                                                                                                                                                                                                                                         
    "instance_ids": [                                                                                                                                                                                                                                                                                                                                                                         
        "REDACTED"                                                                                                                                                                                                                                                                                                                                                                 
    ],
    "instances": [
        {
            "ami_launch_index": 0,
            "architecture": "x86_64",
            "block_device_mappings": [
                {
                    "device_name": "/dev/sda1",
                    "ebs": {
                        "attach_time": "2022-08-10T19:50:24+00:00",
                        "delete_on_termination": true,
                        "status": "attached",
                        "volume_id": "REDACTED"
                    }
                },
                {
                    "device_name": "/dev/xvdo",
                    "ebs": {
                        "attach_time": "2022-08-10T19:50:24+00:00",
                        "delete_on_termination": true,
                        "status": "attached",
                        "volume_id": "REDACTED"
                    }
                },
                {
                    "device_name": "/dev/xvdp",
                    "ebs": {
                        "attach_time": "2022-08-10T19:50:24+00:00",
                        "delete_on_termination": true,
                        "status": "attached",
                        "volume_id": "REDACTED"
                    }
                },
                {
                    "device_name": "/dev/xvdi",
                    "ebs": {
                        "attach_time": "2022-08-10T19:50:24+00:00",
                        "delete_on_termination": true,
                        "status": "attached",
                        "volume_id": "REDACTED"
                    }
                }
            ],
            "capacity_reservation_specification": {
                "capacity_reservation_preference": "open"
            },
            "client_token": "REDACTED",
            "cpu_options": {
                "core_count": 4,
                "threads_per_core": 2
            },
            "ebs_optimized": true,
            "ena_support": true,
            "enclave_options": {
                "enabled": false
            },
            "hibernation_options": {
                "configured": false
            },
            "hypervisor": "xen",
            "iam_instance_profile": {
                "arn": "REDACTED",
                "id": "REDACTED"
            },
            "image_id": "REDACTED",
            "instance_id": "REDACTED",
            "instance_type": "m5.2xlarge",
            "key_name": "REDACTED",
            "launch_time": "2022-08-10T19:50:23+00:00",
            "maintenance_options": {
                "auto_recovery": "default"
            },
            "metadata_options": {
                "http_endpoint": "enabled",
                "http_protocol_ipv6": "disabled",
                "http_put_response_hop_limit": 1,
                "http_tokens": "optional",
                "instance_metadata_tags": "disabled",
                "state": "applied"
            },
            "monitoring": {
                "state": "disabled"
            },
            "network_interfaces": [
                {
                    "attachment": {
                        "attach_time": "2022-08-10T19:50:23+00:00",
                        "attachment_id": "REDACTED",
                        "delete_on_termination": true,
                        "device_index": 0,
                        "network_card_index": 0,
                        "status": "attached"
                    },
                    "description": "",
                    "groups": [
                        {
                            "group_id": "REDACTED",
                            "group_name": "REDACTED"
                        }
                    ],
                    "interface_type": "interface",
                    "ipv6_addresses": [],
                    "mac_address": "REDACTED",
                    "network_interface_id": "REDACTED",
                    "owner_id": "REDACTED",
                    "private_dns_name": "REDACTED",
                    "private_ip_address": "REDACTED",
                    "private_ip_addresses": [
                        {
                            "primary": true,
                            "private_dns_name": "REDACTED",
                            "private_ip_address": "REDACTED"
                        }
                    ],
                    "source_dest_check": true,
                    "status": "in-use",
                    "subnet_id": "REDACTED",
                    "vpc_id": "REDACTED"
                }
            ],
            "placement": {
                "availability_zone": "us-west-2a",
                "group_name": "",
                "tenancy": "default"
            },
            "platform_details": "Linux/UNIX",
            "private_dns_name": "REDACTED",
            "private_dns_name_options": {
                "enable_resource_name_dns_a_record": false,
                "enable_resource_name_dns_aaaa_record": false,
                "hostname_type": "ip-name"
            },
            "private_ip_address": "REDACTED",
            "product_codes": [],
            "public_dns_name": "",
            "root_device_name": "/dev/sda1",
            "root_device_type": "ebs",
            "security_groups": [
                {
                    "group_id": "REDACTED",
                    "group_name": "REDACTED"
                }
            ],
            "source_dest_check": true,
            "state": {
                "code": 16,
                "name": "running"
            },
            "state_transition_reason": "",
            "subnet_id": "REDACTED",
            "tags": {
                "Name": "something",
                "env": "prod",
            },
            "usage_operation": "RunInstances",
            "usage_operation_update_time": "2022-08-10T19:50:23+00:00",
            "virtualization_type": "hvm",
            "vpc_id": "REDACTED"
        }
    ],
    "invocation": {                                                                                                                                                                                                                                                                                                                                                                           
        "module_args": {                                                                                                                                                                                                                                                                                                                                                                      
            "availability_zone": null,                                                                                                                                                                                                                                                                                                                                                        
            "aws_access_key": null,                                                                                                                                                                                                                                                                                                                                                           
            "aws_ca_bundle": null,                                                                                                                                                                                                                                                                                                                                                            
            "aws_config": null,                                                                                                                                                                                                                                                                                                                                                               
            "aws_secret_key": null,                                                                                                                                                                                                                                                                                                                                                           
            "count": null,                                                                                                                                                                                                                                                                                                                                                                    
            "cpu_credit_specification": null,                                                                                                                                                                                                                                                                                                                                                 
            "cpu_options": null,                                                                                                                                                                                                                                                                                                                                                              
            "debug_botocore_endpoint_logs": false,                                                                                                                                                                                                                                                                                                                                            
            "detailed_monitoring": false,                                                                                                                                                                                                                                                                                                                                                     
            "ebs_optimized": true,                                                                                                                                                                                                                                                                                                                                                            
            "ec2_url": null,                                                                                                                                                                                                                                                                                                                                                                  
            "exact_count": 1,                                                                                                                                                                                                                                                                                                                                                                 
            "filters": {                                                                                                                                                                                                                                                                                                                                                                      
                "tag:Name": "something",                                                                                                                                                                                                                                                                                                                                             
                "tag:env": "prod"                                                                                                                                                                                                                                                                                                                                                             
            },
            "image": null,                                                                                                                                                                                                                                                                                                                                                                    
            "image_id": "REDACTED",                                                                                                                                                                                                                                                                                                                                              
            "instance_ids": [],                                                                                                                                                                                                                                                                                                                                                               
            "instance_initiated_shutdown_behavior": null,                                                                                                                                                                                                                                                                                                                                     
            "instance_role": "REDACTED",                                                                                                                                                                                                                                                                                                                                                       
            "instance_type": "m5.2xlarge",                                                                                                                                                                                                                                                                                                                                                    
            "key_name": "REDACTED",                                                                                                                                                                                                                                                                                                                                                          
            "launch_template": null,                                                                                                                                                                                                                                                                                                                                                          
            "metadata_options": null,                                                                                                                                                                                                                                                                                                                                                         
            "name": null,                                                                                                                                                                                                                                                                                                                                                                     
            "network": {                                                                                                                                                                                                                                                                                                                                                                      
                "source_dest_check": true                                                                                                                                                                                                                                                                                                                                                     
            },                                                                                                                                                                                                                                                                                                                                                                                
            "placement_group": null,                                                                                                                                                                                                                                                                                                                                                          
            "profile": null,                                                                                                                                                                                                                                                                                                                                                                  
            "purge_tags": false,                                                                                                                                                                                                                                                                                                                                                              
            "region": "us-west-2",                                                                                                                                                                                                                                                                                                                                                            
            "security_group": null,                                                                                                                                                                                                                                                                                                                                                           
            "security_groups": [                                                                                                                                                                                                                                                                                                                                                              
                "default"                                                                                                                                                                                                                                                                                                                                                                     
            ],                                                                                                                                                                                                                                                                                                                                                                                
            "security_token": null,                                                                                                                                                                                                                                                                                                                                                           
            "state": "present",                                                                                                                                                                
            "tags": {                                                                                                                                                                                                                                                                                                                                                                         
                "Name": "something",                                                                                                                                                                                                                                                                                                                                                         
                "env": "prod",
            },
            "tenancy": null,
            "termination_protection": null,
            "tower_callback": null,
            "user_data": "REDACTED",
            "validate_certs": true,
            "volumes": [
                {
                    "device_name": "/dev/sda1",
                    "ebs": {
                        "delete_on_termination": true,
                        "encrypted": true,
                        "volume_size": 20,
                        "volume_type": "gp3"
                    }
                },
                {
                    "device_name": "/dev/xvdo",
                    "ebs": {
                        "delete_on_termination": true,
                        "encrypted": true,
                        "volume_size": 20,
                        "volume_type": "gp3"
                    }
                },
                {
                    "device_name": "/dev/xvdp",
                    "ebs": {
                        "delete_on_termination": true,
                        "encrypted": true,
                        "volume_size": 10,
                        "volume_type": "gp3"
                    }
                },
                {
                    "device_name": "/dev/xvdi",
                    "ebs": {
                        "delete_on_termination": true,
                        "encrypted": true,
                        "volume_size": 100,
                        "volume_type": "gp3"
                    }
                }
            ],
            "vpc_subnet_id": "REDACTED",
            "wait": true,
            "wait_timeout": 300
        }
    },
    "msg": "1 instances already running, nothing to do."
}

Reviewed-by: Alina Buzachis
Reviewed-by: Mark Chappell
tremble pushed a commit to tremble/amazon.aws that referenced this issue Feb 24, 2023
fix incomplete enforce_count() return values

SUMMARY

This is the Ansible way.
Since a call to enforce_count() requires that a call to find_instances() has already been made, the information required to populate the instances return key is already held by the variable existing_matches. There are zero use cases where it makes sense not to output this information; if I want exactly one such instance and an existing instance matches the filter, I definitely always want to know its details.

Fixes ansible-collections#963, ansible-collections#859
ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME

ec2_instance
ADDITIONAL INFORMATION

See linked issues.

Before:
{
    "changed": false,
    "invocation": {
        "module_args": {
            "availability_zone": null,
            "aws_access_key": null,
            "aws_ca_bundle": null,
            "aws_config": null,
            "aws_secret_key": null,
            "count": null,
            "cpu_credit_specification": null,
            "cpu_options": null,
            "debug_botocore_endpoint_logs": false,
            "detailed_monitoring": false,
            "ebs_optimized": true,
            "ec2_url": null,
            "exact_count": 1,
            "filters": {
                "tag:Name": "something",
                "tag:env": "prod"
            },
            "image": null,
            "image_id": "REDACTED",
            "instance_ids": [],
            "instance_initiated_shutdown_behavior": null,
            "instance_role": "REDACTED",
            "instance_type": "m5.2xlarge",
            "key_name": "REDACTED",
            "launch_template": null,
            "metadata_options": null,
            "name": null,
            "network": {
                "source_dest_check": true
            },
            "placement_group": null,
            "profile": null,
            "purge_tags": false,
            "region": "us-west-2",
            "security_group": null,
            "security_groups": [
                "default"
            ],
            "security_token": null,
            "state": "present",
            "tags": {
                "Name": "something",
                "env": "prod",
            },
            "tenancy": null,
            "termination_protection": null,
            "tower_callback": null,
            "user_data": "REDACTED",
            "validate_certs": true,
            "volumes": [
                {
                    "device_name": "/dev/sda1",
                    "ebs": {
                        "delete_on_termination": true,
                        "encrypted": true,
                        "volume_size": 20,
                        "volume_type": "gp3"
                    }
                },
                {
                    "device_name": "/dev/xvdo",
                    "ebs": {
                        "delete_on_termination": true,
                        "encrypted": true,
                        "volume_size": 20,
                        "volume_type": "gp3"
                    }
                },
                {
                    "device_name": "/dev/xvdp",
                    "ebs": {
                        "delete_on_termination": true,
                        "encrypted": true,
                        "volume_size": 10,
                        "volume_type": "gp3"
                    }
                },
                {
                    "device_name": "/dev/xvdi",
                    "ebs": {
                        "delete_on_termination": true,
                        "encrypted": true,
                        "volume_size": 100,
                        "volume_type": "gp3"
                    }
                }
            ],
            "vpc_subnet_id": "REDACTED",
            "wait": true,
            "wait_timeout": 300
        }
    },
    "msg": "1 instances already running, nothing to do."
}
After:
{
    "changed": false,
    "instance_ids": [
        "REDACTED"
    ],
    "instances": [
        {
            "ami_launch_index": 0,
            "architecture": "x86_64",
            "block_device_mappings": [
                {
                    "device_name": "/dev/sda1",
                    "ebs": {
                        "attach_time": "2022-08-10T19:50:24+00:00",
                        "delete_on_termination": true,
                        "status": "attached",
                        "volume_id": "REDACTED"
                    }
                },
                {
                    "device_name": "/dev/xvdo",
                    "ebs": {
                        "attach_time": "2022-08-10T19:50:24+00:00",
                        "delete_on_termination": true,
                        "status": "attached",
                        "volume_id": "REDACTED"
                    }
                },
                {
                    "device_name": "/dev/xvdp",
                    "ebs": {
                        "attach_time": "2022-08-10T19:50:24+00:00",
                        "delete_on_termination": true,
                        "status": "attached",
                        "volume_id": "REDACTED"
                    }
                },
                {
                    "device_name": "/dev/xvdi",
                    "ebs": {
                        "attach_time": "2022-08-10T19:50:24+00:00",
                        "delete_on_termination": true,
                        "status": "attached",
                        "volume_id": "REDACTED"
                    }
                }
            ],
            "capacity_reservation_specification": {
                "capacity_reservation_preference": "open"
            },
            "client_token": "REDACTED",
            "cpu_options": {
                "core_count": 4,
                "threads_per_core": 2
            },
            "ebs_optimized": true,
            "ena_support": true,
            "enclave_options": {
                "enabled": false
            },
            "hibernation_options": {
                "configured": false
            },
            "hypervisor": "xen",
            "iam_instance_profile": {
                "arn": "REDACTED",
                "id": "REDACTED"
            },
            "image_id": "REDACTED",
            "instance_id": "REDACTED",
            "instance_type": "m5.2xlarge",
            "key_name": "REDACTED",
            "launch_time": "2022-08-10T19:50:23+00:00",
            "maintenance_options": {
                "auto_recovery": "default"
            },
            "metadata_options": {
                "http_endpoint": "enabled",
                "http_protocol_ipv6": "disabled",
                "http_put_response_hop_limit": 1,
                "http_tokens": "optional",
                "instance_metadata_tags": "disabled",
                "state": "applied"
            },
            "monitoring": {
                "state": "disabled"
            },
            "network_interfaces": [
                {
                    "attachment": {
                        "attach_time": "2022-08-10T19:50:23+00:00",
                        "attachment_id": "REDACTED",
                        "delete_on_termination": true,
                        "device_index": 0,
                        "network_card_index": 0,
                        "status": "attached"
                    },
                    "description": "",
                    "groups": [
                        {
                            "group_id": "REDACTED",
                            "group_name": "REDACTED"
                        }
                    ],
                    "interface_type": "interface",
                    "ipv6_addresses": [],
                    "mac_address": "REDACTED",
                    "network_interface_id": "REDACTED",
                    "owner_id": "REDACTED",
                    "private_dns_name": "REDACTED",
                    "private_ip_address": "REDACTED",
                    "private_ip_addresses": [
                        {
                            "primary": true,
                            "private_dns_name": "REDACTED",
                            "private_ip_address": "REDACTED"
                        }
                    ],
                    "source_dest_check": true,
                    "status": "in-use",
                    "subnet_id": "REDACTED",
                    "vpc_id": "REDACTED"
                }
            ],
            "placement": {
                "availability_zone": "us-west-2a",
                "group_name": "",
                "tenancy": "default"
            },
            "platform_details": "Linux/UNIX",
            "private_dns_name": "REDACTED",
            "private_dns_name_options": {
                "enable_resource_name_dns_a_record": false,
                "enable_resource_name_dns_aaaa_record": false,
                "hostname_type": "ip-name"
            },
            "private_ip_address": "REDACTED",
            "product_codes": [],
            "public_dns_name": "",
            "root_device_name": "/dev/sda1",
            "root_device_type": "ebs",
            "security_groups": [
                {
                    "group_id": "REDACTED",
                    "group_name": "REDACTED"
                }
            ],
            "source_dest_check": true,
            "state": {
                "code": 16,
                "name": "running"
            },
            "state_transition_reason": "",
            "subnet_id": "REDACTED",
            "tags": {
                "Name": "something",
                "env": "prod",
            },
            "usage_operation": "RunInstances",
            "usage_operation_update_time": "2022-08-10T19:50:23+00:00",
            "virtualization_type": "hvm",
            "vpc_id": "REDACTED"
        }
    ],
    "invocation": {
        "module_args": {
            "availability_zone": null,
            "aws_access_key": null,
            "aws_ca_bundle": null,
            "aws_config": null,
            "aws_secret_key": null,
            "count": null,
            "cpu_credit_specification": null,
            "cpu_options": null,
            "debug_botocore_endpoint_logs": false,
            "detailed_monitoring": false,
            "ebs_optimized": true,
            "ec2_url": null,
            "exact_count": 1,
            "filters": {
                "tag:Name": "something",
                "tag:env": "prod"
            },
            "image": null,
            "image_id": "REDACTED",
            "instance_ids": [],
            "instance_initiated_shutdown_behavior": null,
            "instance_role": "REDACTED",
            "instance_type": "m5.2xlarge",
            "key_name": "REDACTED",
            "launch_template": null,
            "metadata_options": null,
            "name": null,
            "network": {
                "source_dest_check": true
            },
            "placement_group": null,
            "profile": null,
            "purge_tags": false,
            "region": "us-west-2",
            "security_group": null,
            "security_groups": [
                "default"
            ],
            "security_token": null,
            "state": "present",
            "tags": {
                "Name": "something",
                "env": "prod",
            },
            "tenancy": null,
            "termination_protection": null,
            "tower_callback": null,
            "user_data": "REDACTED",
            "validate_certs": true,
            "volumes": [
                {
                    "device_name": "/dev/sda1",
                    "ebs": {
                        "delete_on_termination": true,
                        "encrypted": true,
                        "volume_size": 20,
                        "volume_type": "gp3"
                    }
                },
                {
                    "device_name": "/dev/xvdo",
                    "ebs": {
                        "delete_on_termination": true,
                        "encrypted": true,
                        "volume_size": 20,
                        "volume_type": "gp3"
                    }
                },
                {
                    "device_name": "/dev/xvdp",
                    "ebs": {
                        "delete_on_termination": true,
                        "encrypted": true,
                        "volume_size": 10,
                        "volume_type": "gp3"
                    }
                },
                {
                    "device_name": "/dev/xvdi",
                    "ebs": {
                        "delete_on_termination": true,
                        "encrypted": true,
                        "volume_size": 100,
                        "volume_type": "gp3"
                    }
                }
            ],
            "vpc_subnet_id": "REDACTED",
            "wait": true,
            "wait_timeout": 300
        }
    },
    "msg": "1 instances already running, nothing to do."
}

Reviewed-by: Alina Buzachis
Reviewed-by: Mark Chappell
tremble added a commit that referenced this issue Feb 27, 2023
SUMMARY

This is the Ansible way.
Since a call to enforce_count() requires that a call to find_instances() has already been made, the information required to populate the instances return key is already held by the variable existing_matches. There are zero use cases where it makes sense not to output this information; if I want exactly one such instance and an existing instance matches the filter, I definitely always want to know its details.

Fixes #963, #859

ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME

ec2_instance

ADDITIONAL INFORMATION

See linked issues.

Before:
{
    "changed": false,
    "invocation": {
        "module_args": {
            "availability_zone": null,
            "aws_access_key": null,
            "aws_ca_bundle": null,
            "aws_config": null,
            "aws_secret_key": null,
            "count": null,
            "cpu_credit_specification": null,
            "cpu_options": null,
            "debug_botocore_endpoint_logs": false,
            "detailed_monitoring": false,
            "ebs_optimized": true,
            "ec2_url": null,
            "exact_count": 1,
            "filters": {
                "tag:Name": "something",
                "tag:env": "prod"
            },
            "image": null,
            "image_id": "REDACTED",
            "instance_ids": [],
            "instance_initiated_shutdown_behavior": null,
            "instance_role": "REDACTED",
            "instance_type": "m5.2xlarge",
            "key_name": "REDACTED",
            "launch_template": null,
            "metadata_options": null,
            "name": null,
            "network": {
                "source_dest_check": true
            },
            "placement_group": null,
            "profile": null,
            "purge_tags": false,
            "region": "us-west-2",
            "security_group": null,
            "security_groups": [
                "default"
            ],
            "security_token": null,
            "state": "present",
            "tags": {
                "Name": "something",
                "env": "prod",
            },
            "tenancy": null,
            "termination_protection": null,
            "tower_callback": null,
            "user_data": "REDACTED",
            "validate_certs": true,
            "volumes": [
                {
                    "device_name": "/dev/sda1",
                    "ebs": {
                        "delete_on_termination": true,
                        "encrypted": true,
                        "volume_size": 20,
                        "volume_type": "gp3"
                    }
                },
                {
                    "device_name": "/dev/xvdo",
                    "ebs": {
                        "delete_on_termination": true,
                        "encrypted": true,
                        "volume_size": 20,
                        "volume_type": "gp3"
                    }
                },
                {
                    "device_name": "/dev/xvdp",
                    "ebs": {
                        "delete_on_termination": true,
                        "encrypted": true,
                        "volume_size": 10,
                        "volume_type": "gp3"
                    }
                },
                {
                    "device_name": "/dev/xvdi",
                    "ebs": {
                        "delete_on_termination": true,
                        "encrypted": true,
                        "volume_size": 100,
                        "volume_type": "gp3"
                    }
                }
            ],
            "vpc_subnet_id": "REDACTED",
            "wait": true,
            "wait_timeout": 300
        }
    },
    "msg": "1 instances already running, nothing to do."
}
After:
{
    "changed": false,
    "instance_ids": [
        "REDACTED"
    ],
    "instances": [
        {
            "ami_launch_index": 0,
            "architecture": "x86_64",
            "block_device_mappings": [
                {
                    "device_name": "/dev/sda1",
                    "ebs": {
                        "attach_time": "2022-08-10T19:50:24+00:00",
                        "delete_on_termination": true,
                        "status": "attached",
                        "volume_id": "REDACTED"
                    }
                },
                {
                    "device_name": "/dev/xvdo",
                    "ebs": {
                        "attach_time": "2022-08-10T19:50:24+00:00",
                        "delete_on_termination": true,
                        "status": "attached",
                        "volume_id": "REDACTED"
                    }
                },
                {
                    "device_name": "/dev/xvdp",
                    "ebs": {
                        "attach_time": "2022-08-10T19:50:24+00:00",
                        "delete_on_termination": true,
                        "status": "attached",
                        "volume_id": "REDACTED"
                    }
                },
                {
                    "device_name": "/dev/xvdi",
                    "ebs": {
                        "attach_time": "2022-08-10T19:50:24+00:00",
                        "delete_on_termination": true,
                        "status": "attached",
                        "volume_id": "REDACTED"
                    }
                }
            ],
            "capacity_reservation_specification": {
                "capacity_reservation_preference": "open"
            },
            "client_token": "REDACTED",
            "cpu_options": {
                "core_count": 4,
                "threads_per_core": 2
            },
            "ebs_optimized": true,
            "ena_support": true,
            "enclave_options": {
                "enabled": false
            },
            "hibernation_options": {
                "configured": false
            },
            "hypervisor": "xen",
            "iam_instance_profile": {
                "arn": "REDACTED",
                "id": "REDACTED"
            },
            "image_id": "REDACTED",
            "instance_id": "REDACTED",
            "instance_type": "m5.2xlarge",
            "key_name": "REDACTED",
            "launch_time": "2022-08-10T19:50:23+00:00",
            "maintenance_options": {
                "auto_recovery": "default"
            },
            "metadata_options": {
                "http_endpoint": "enabled",
                "http_protocol_ipv6": "disabled",
                "http_put_response_hop_limit": 1,
                "http_tokens": "optional",
                "instance_metadata_tags": "disabled",
                "state": "applied"
            },
            "monitoring": {
                "state": "disabled"
            },
            "network_interfaces": [
                {
                    "attachment": {
                        "attach_time": "2022-08-10T19:50:23+00:00",
                        "attachment_id": "REDACTED",
                        "delete_on_termination": true,
                        "device_index": 0,
                        "network_card_index": 0,
                        "status": "attached"
                    },
                    "description": "",
                    "groups": [
                        {
                            "group_id": "REDACTED",
                            "group_name": "REDACTED"
                        }
                    ],
                    "interface_type": "interface",
                    "ipv6_addresses": [],
                    "mac_address": "REDACTED",
                    "network_interface_id": "REDACTED",
                    "owner_id": "REDACTED",
                    "private_dns_name": "REDACTED",
                    "private_ip_address": "REDACTED",
                    "private_ip_addresses": [
                        {
                            "primary": true,
                            "private_dns_name": "REDACTED",
                            "private_ip_address": "REDACTED"
                        }
                    ],
                    "source_dest_check": true,
                    "status": "in-use",
                    "subnet_id": "REDACTED",
                    "vpc_id": "REDACTED"
                }
            ],
            "placement": {
                "availability_zone": "us-west-2a",
                "group_name": "",
                "tenancy": "default"
            },
            "platform_details": "Linux/UNIX",
            "private_dns_name": "REDACTED",
            "private_dns_name_options": {
                "enable_resource_name_dns_a_record": false,
                "enable_resource_name_dns_aaaa_record": false,
                "hostname_type": "ip-name"
            },
            "private_ip_address": "REDACTED",
            "product_codes": [],
            "public_dns_name": "",
            "root_device_name": "/dev/sda1",
            "root_device_type": "ebs",
            "security_groups": [
                {
                    "group_id": "REDACTED",
                    "group_name": "REDACTED"
                }
            ],
            "source_dest_check": true,
            "state": {
                "code": 16,
                "name": "running"
            },
            "state_transition_reason": "",
            "subnet_id": "REDACTED",
            "tags": {
                "Name": "something",
                "env": "prod",
            },
            "usage_operation": "RunInstances",
            "usage_operation_update_time": "2022-08-10T19:50:23+00:00",
            "virtualization_type": "hvm",
            "vpc_id": "REDACTED"
        }
    ],
    "invocation": {
        "module_args": {
            "availability_zone": null,
            "aws_access_key": null,
            "aws_ca_bundle": null,
            "aws_config": null,
            "aws_secret_key": null,
            "count": null,
            "cpu_credit_specification": null,
            "cpu_options": null,
            "debug_botocore_endpoint_logs": false,
            "detailed_monitoring": false,
            "ebs_optimized": true,
            "ec2_url": null,
            "exact_count": 1,
            "filters": {
                "tag:Name": "something",
                "tag:env": "prod"
            },
            "image": null,
            "image_id": "REDACTED",
            "instance_ids": [],
            "instance_initiated_shutdown_behavior": null,
            "instance_role": "REDACTED",
            "instance_type": "m5.2xlarge",
            "key_name": "REDACTED",
            "launch_template": null,
            "metadata_options": null,
            "name": null,
            "network": {
                "source_dest_check": true
            },
            "placement_group": null,
            "profile": null,
            "purge_tags": false,
            "region": "us-west-2",
            "security_group": null,
            "security_groups": [
                "default"
            ],
            "security_token": null,
            "state": "present",
            "tags": {
                "Name": "something",
                "env": "prod",
            },
            "tenancy": null,
            "termination_protection": null,
            "tower_callback": null,
            "user_data": "REDACTED",
            "validate_certs": true,
            "volumes": [
                {
                    "device_name": "/dev/sda1",
                    "ebs": {
                        "delete_on_termination": true,
                        "encrypted": true,
                        "volume_size": 20,
                        "volume_type": "gp3"
                    }
                },
                {
                    "device_name": "/dev/xvdo",
                    "ebs": {
                        "delete_on_termination": true,
                        "encrypted": true,
                        "volume_size": 20,
                        "volume_type": "gp3"
                    }
                },
                {
                    "device_name": "/dev/xvdp",
                    "ebs": {
                        "delete_on_termination": true,
                        "encrypted": true,
                        "volume_size": 10,
                        "volume_type": "gp3"
                    }
                },
                {
                    "device_name": "/dev/xvdi",
                    "ebs": {
                        "delete_on_termination": true,
                        "encrypted": true,
                        "volume_size": 100,
                        "volume_type": "gp3"
                    }
                }
            ],
            "vpc_subnet_id": "REDACTED",
            "wait": true,
            "wait_timeout": 300
        }
    },
    "msg": "1 instances already running, nothing to do."
}

Reviewed-by: Alina Buzachis
Reviewed-by: Mark Chappell

Co-authored-by: Matt 'Archer' Vaughn <[email protected]>
abikouo pushed a commit to abikouo/amazon.aws that referenced this issue Sep 18, 2023
Add 'opensearch' and 'opensearch_info' modules

SUMMARY


Add opensearch module to create/update AWS OpenSearch/Elasticsearch  domains.
Add opensearch_info module to query AWS OpenSearch/Elasticsearch domains.

Fixes ansible-collections#858
Requires mattclay/aws-terminator#187

ISSUE TYPE


New Module Pull Request

COMPONENT NAME

Creates OpenSearch or ElasticSearch domain.
ADDITIONAL INFORMATION



The minimum version of botocore for these modules is 1.21.38.
The integration tests take more than 4 hours to execute. Tests time out in the CI. I was able to run the integration tests locally.

Reviewed-by: Alina Buzachis <None>
Reviewed-by: Sebastien Rosset <None>
Reviewed-by: Mark Chappell <None>
Reviewed-by: Markus Bergholz <[email protected]>
abikouo pushed a commit to abikouo/amazon.aws that referenced this issue Sep 18, 2023
opensearch - Minor fixups

SUMMARY
Minor fixups from ansible-collections#859
Module hasn't been release yet, no need for changelog
ISSUE TYPE

Docs Pull Request
Feature Pull Request

COMPONENT NAME
opensearch
opensearch_info
ADDITIONAL INFORMATION

Reviewed-by: Alina Buzachis <None>
abikouo pushed a commit to abikouo/amazon.aws that referenced this issue Sep 18, 2023
Add 'opensearch' and 'opensearch_info' modules

SUMMARY


Add opensearch module to create/update AWS OpenSearch/Elasticsearch  domains.
Add opensearch_info module to query AWS OpenSearch/Elasticsearch domains.

Fixes ansible-collections#858
Requires mattclay/aws-terminator#187

ISSUE TYPE


New Module Pull Request

COMPONENT NAME

Creates OpenSearch or ElasticSearch domain.
ADDITIONAL INFORMATION



The minimum version of botocore for these modules is 1.21.38.
The integration tests take more than 4 hours to execute. Tests time out in the CI. I was able to run the integration tests locally.

Reviewed-by: Alina Buzachis <None>
Reviewed-by: Sebastien Rosset <None>
Reviewed-by: Mark Chappell <None>
Reviewed-by: Markus Bergholz <[email protected]>
abikouo pushed a commit to abikouo/amazon.aws that referenced this issue Sep 18, 2023
opensearch - Minor fixups

SUMMARY
Minor fixups from ansible-collections#859
Module hasn't been release yet, no need for changelog
ISSUE TYPE

Docs Pull Request
Feature Pull Request

COMPONENT NAME
opensearch
opensearch_info
ADDITIONAL INFORMATION

Reviewed-by: Alina Buzachis <None>
abikouo pushed a commit to abikouo/amazon.aws that referenced this issue Oct 24, 2023
Add 'opensearch' and 'opensearch_info' modules

SUMMARY


Add opensearch module to create/update AWS OpenSearch/Elasticsearch  domains.
Add opensearch_info module to query AWS OpenSearch/Elasticsearch domains.

Fixes ansible-collections#858
Requires mattclay/aws-terminator#187

ISSUE TYPE


New Module Pull Request

COMPONENT NAME

Creates OpenSearch or ElasticSearch domain.
ADDITIONAL INFORMATION



The minimum version of botocore for these modules is 1.21.38.
The integration tests take more than 4 hours to execute. Tests time out in the CI. I was able to run the integration tests locally.

Reviewed-by: Alina Buzachis <None>
Reviewed-by: Sebastien Rosset <None>
Reviewed-by: Mark Chappell <None>
Reviewed-by: Markus Bergholz <[email protected]>
abikouo pushed a commit to abikouo/amazon.aws that referenced this issue Oct 24, 2023
opensearch - Minor fixups

SUMMARY
Minor fixups from ansible-collections#859
Module hasn't been release yet, no need for changelog
ISSUE TYPE

Docs Pull Request
Feature Pull Request

COMPONENT NAME
opensearch
opensearch_info
ADDITIONAL INFORMATION

Reviewed-by: Alina Buzachis <None>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue/PR relates to a bug module module needs_triage plugins plugin (any type) python3
Projects
None yet
Development

No branches or pull requests

4 participants