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

[Manual backport] Backport pr-2488 to stable-8 #2490

Conversation

mandar242
Copy link
Contributor

Manual backport of #2488

SUMMARY

Fixes https://issues.redhat.com/browse/ACA-2123

This PR addresses an issue where module tries to attach all security groups in the region that default SGs for any VPC in the region. Causing error below

fatal: [localhost]: FAILED! => {"boto3_version": "1.34.144", "botocore_version": "1.34.144", "changed": false,
"msg": "Could not apply change {'Groups': ['sg-xxxx', 'sg-yyyy', 'sg-zzzz']} to existing instance.: Failed to modify instance attribute"}

The subnet_id was previously passed as None when not found in the network_interface, causing failures when applying security group. The logic was updated to use module.params.get("vpc_subnet_id") when provided in task, as a fallback, preventing None from being passed to discover_security_groups() and ensuring the correct subnet is used when the default security group is specified.

ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME

ec2_instance
ADDITIONAL INFORMATION

According to jira, the issue was introduced after 8.1.0 onwards (worked fine until and including 8.1.0) Issue was only seen (during testing/reproducing) when network and vpc_subnet_id were both specified in the task.

Playbook used for testing/reproducing the issue.

  • name: EC2 instance hosts: localhost gather_facts: no vars: instance_type: "t2.micro" subnet_id: "subnet-xxxxxxx" region: "ap-northeast-2" image_id: "ami-xxxxxxx" tasks:
    • name: Create the EC2 instance with proper tags amazon.aws.ec2_instance: image_id: "{{ image_id }}" instance_type: "{{ instance_type }}" network: assign_public_ip: false private_ip_address: "{{ ec2_private_ip | default(omit) }}" purge_tags: false region: "{{ region }}" security_groups: "{{ security_group | default('default') }}" tags: Owner: mandkulk Persistent: False Name: xxxxx-test-instance vpc_subnet_id: "{{ subnet_id }}" wait: true state: present register: ec2

Reviewed-by: Mark Chappell
Reviewed-by: Alina Buzachis
(cherry picked from commit 2fb1661)

SUMMARY
ISSUE TYPE
  • Bugfix Pull Request
  • Docs Pull Request
  • Feature Pull Request
  • New Module Pull Request
COMPONENT NAME
ADDITIONAL INFORMATION

…s missing from network interface (ansible-collections#2488)

SUMMARY

Fixes https://issues.redhat.com/browse/ACA-2123

This PR addresses an issue where module tries to attach all security groups in the region that default SGs for any VPC in the region. Causing error below

fatal: [localhost]: FAILED! => {"boto3_version": "1.34.144", "botocore_version": "1.34.144", "changed": false,
"msg": "Could not apply change {'Groups': ['sg-xxxx', 'sg-yyyy', 'sg-zzzz']} to existing instance.: Failed to modify instance attribute"}

The subnet_id was previously passed as None when not found in the network_interface, causing failures when applying security group.
The logic was updated to use module.params.get("vpc_subnet_id") when provided in task, as a fallback, preventing None from being passed to discover_security_groups() and ensuring the correct subnet is used when the default security group is specified.

ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME

ec2_instance
ADDITIONAL INFORMATION

According to jira, the issue was introduced after 8.1.0 onwards (worked fine until and including 8.1.0)
Issue was only seen (during testing/reproducing) when network and vpc_subnet_id were both specified in the task.

Playbook used for testing/reproducing the issue.
---
- name: EC2 instance
  hosts: localhost
  gather_facts: no
  vars:
    instance_type: "t2.micro"
    subnet_id: "subnet-xxxxxxx"
    region: "ap-northeast-2"
     image_id: "ami-xxxxxxx"
  tasks:
    - name: Create the EC2 instance with proper tags
      amazon.aws.ec2_instance:
        image_id: "{{ image_id }}"
        instance_type: "{{ instance_type }}"
        network:
          assign_public_ip: false
          private_ip_address: "{{ ec2_private_ip | default(omit) }}"
        purge_tags: false
        region: "{{ region }}"
        security_groups: "{{ security_group | default('default') }}"
        tags:
          Owner: mandkulk
          Persistent: False
          Name: xxxxx-test-instance
        vpc_subnet_id: "{{ subnet_id }}"
        wait: true
        state: present
      register: ec2

Reviewed-by: Mark Chappell
Reviewed-by: Alina Buzachis
(cherry picked from commit 2fb1661)
@mandar242 mandar242 changed the title [Manual backport] patchback/backports/stable-8/2fb1661c4fdefdf8c383a5449b55b2cbe34ad71a/pr-2488 [Manual backport] Backport pr-2488 to stable-8 Jan 29, 2025
Copy link

github-actions bot commented Jan 29, 2025

Docs Build 📝

Thank you for contribution!✨

This PR has been merged and your docs changes will be incorporated when they are next published.

Copy link
Contributor

Build succeeded.
https://ansible.softwarefactory-project.io/zuul/buildset/bba7b8656dfa4573ae75b202904c2bb5

✔️ ansible-galaxy-importer SUCCESS in 5m 06s
✔️ build-ansible-collection SUCCESS in 10m 06s
✔️ ansible-test-splitter SUCCESS in 3m 52s
✔️ integration-amazon.aws-1 SUCCESS in 27m 10s
✔️ integration-amazon.aws-2 SUCCESS in 9m 08s
✔️ integration-amazon.aws-3 SUCCESS in 9m 17s
✔️ integration-amazon.aws-4 SUCCESS in 9m 03s
✔️ integration-amazon.aws-5 SUCCESS in 9m 11s
✔️ integration-amazon.aws-6 SUCCESS in 7m 55s
✔️ integration-amazon.aws-7 SUCCESS in 8m 18s
✔️ integration-amazon.aws-8 SUCCESS in 9m 53s
✔️ integration-amazon.aws-9 SUCCESS in 7m 40s
✔️ integration-amazon.aws-10 SUCCESS in 6m 50s
✔️ integration-amazon.aws-11 SUCCESS in 11m 51s
✔️ integration-amazon.aws-12 SUCCESS in 11m 09s
✔️ integration-amazon.aws-13 SUCCESS in 10m 36s
✔️ integration-amazon.aws-14 SUCCESS in 10m 42s
✔️ integration-amazon.aws-15 SUCCESS in 9m 45s
✔️ integration-amazon.aws-16 SUCCESS in 11m 33s
✔️ integration-amazon.aws-17 SUCCESS in 7m 14s
✔️ integration-amazon.aws-18 SUCCESS in 7m 38s
✔️ integration-amazon.aws-19 SUCCESS in 7m 06s
✔️ integration-amazon.aws-20 SUCCESS in 9m 24s
Skipped 24 jobs

@mandar242 mandar242 added the mergeit Merge the PR (SoftwareFactory) label Jan 30, 2025
Copy link
Contributor

Build succeeded (gate pipeline).
https://ansible.softwarefactory-project.io/zuul/buildset/fda394569b1c46bf84afc1ccd2332e67

✔️ ansible-galaxy-importer SUCCESS in 4m 58s
✔️ build-ansible-collection SUCCESS in 10m 12s
✔️ ansible-test-splitter SUCCESS in 4m 19s
✔️ integration-amazon.aws-1 SUCCESS in 29m 52s
✔️ integration-amazon.aws-2 SUCCESS in 8m 21s
✔️ integration-amazon.aws-3 SUCCESS in 8m 53s
✔️ integration-amazon.aws-4 SUCCESS in 7m 41s
✔️ integration-amazon.aws-5 SUCCESS in 7m 07s
✔️ integration-amazon.aws-6 SUCCESS in 5m 57s
✔️ integration-amazon.aws-7 SUCCESS in 7m 14s
✔️ integration-amazon.aws-8 SUCCESS in 8m 03s
✔️ integration-amazon.aws-9 SUCCESS in 8m 15s
✔️ integration-amazon.aws-10 SUCCESS in 11m 43s
✔️ integration-amazon.aws-11 SUCCESS in 11m 37s
✔️ integration-amazon.aws-12 SUCCESS in 12m 11s
✔️ integration-amazon.aws-13 SUCCESS in 6m 23s
✔️ integration-amazon.aws-14 SUCCESS in 10m 24s
✔️ integration-amazon.aws-15 SUCCESS in 8m 28s
✔️ integration-amazon.aws-16 SUCCESS in 7m 36s
✔️ integration-amazon.aws-17 SUCCESS in 10m 18s
✔️ integration-amazon.aws-18 SUCCESS in 9m 30s
✔️ integration-amazon.aws-19 SUCCESS in 8m 02s
✔️ integration-amazon.aws-20 SUCCESS in 9m 09s
Skipped 24 jobs

@softwarefactory-project-zuul softwarefactory-project-zuul bot merged commit 1ee5a9f into ansible-collections:stable-8 Jan 30, 2025
45 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mergeit Merge the PR (SoftwareFactory)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants