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 - attach network interfaces issue when using check_mode #1403

Closed
1 task done
abikouo opened this issue Mar 3, 2023 · 2 comments · Fixed by #1576
Closed
1 task done

ec2_instance - attach network interfaces issue when using check_mode #1403

abikouo opened this issue Mar 3, 2023 · 2 comments · Fixed by #1576
Assignees
Labels
bug This issue/PR relates to a bug has_pr

Comments

@abikouo
Copy link
Contributor

abikouo commented Mar 3, 2023

Summary

When trying to attach a new network interface to a running instance with check_mode, the module performs the update instead of just validating if this will be done.

Issue Type

Bug Report

Component Name

ec2_instance

Ansible Version

$ ansible --version

Collection Versions

$ ansible-galaxy collection list

AWS SDK versions

$ pip show boto boto3 botocore

Configuration

$ ansible-config dump --only-changed

OS / Environment

No response

Steps to Reproduce

- hosts: localhost
  gather_facts: false

  collections:
    - amazon.aws
 
  vars:
    vpc_name: "aubin-test-ec2-0303-2"
    vpc_cidr: "10.1.0.0/16"
    subnet_cidr: "10.1.1.0/24"
    security_group_name: "aubin-test-sg-01"
    ec2_name: "aubin-0303-ec2"
    ec2_instance_type: "t3.nano"
    ec2_ami_id: "ami-0b1236a14f61e87b5"

  tasks:
    - name: "Create VPC for use in testing"
      ec2_vpc_net:
        state: present
        name: "{{ vpc_name }}"
        cidr_block: "{{ vpc_cidr }}"
        tags:
          Name: "{{ vpc_name }}"
        tenancy: default
      register: testing_vpc

    - name: "Create default subnet"
      ec2_vpc_subnet:
        state: present
        vpc_id: "{{ testing_vpc.vpc.id }}"
        cidr: "{{ subnet_cidr }}"
      register: testing_subnet
    
    - name: "create a security group with the vpc"
      ec2_security_group:
        name: "{{ security_group_name }}"
        description: security group for ansible tests
        vpc_id: "{{ testing_vpc.vpc.id }}"
        rules:
          - proto: tcp
            from_port: 22
            to_port: 22
            cidr_ip: 0.0.0.0/0
          - proto: tcp
            from_port: 80
            to_port: 80
            cidr_ip: 0.0.0.0/0
      register: sg

    - name: create an Elastic network interface
      ec2_eni:
        state: present
        delete_on_termination: true
        subnet_id: "{{ testing_subnet.subnet.id }}"
        security_groups:
          - "{{ sg.group_id }}"
      register: enis
      with_items: "{{ range(2) }}"
    
    - name: Create instance
      ec2_instance:
        state: running
        name: "{{ ec2_name }}"
        image_id: "{{ ec2_ami_id }}"
        vpc_subnet_id: "{{ testing_subnet.subnet.id }}"
        instance_type: "{{ ec2_instance_type }}"
        network:
          interfaces:
            - id: "{{ enis.results.0.interface.id }}"
        wait: true
      register: create_instance
    
    - assert:
        that:
          - create_instance is changed
    
    - name: "Gather instance info"
      ec2_instance_info:
        filters:
          "tag:Name": "{{ ec2_name }}"
          instance-state-name: running
      register: _instances_info
    
    - assert:
        that:
          - _instances_info.instances | length == 1

    - name: Attach network interface(s) to the instance
      ec2_instance:
        state: running
        name: "{{ ec2_name }}"
        image_id: "{{ ec2_ami_id }}"
        vpc_subnet_id: "{{ testing_subnet.subnet.id }}"
        network:
          interfaces:
            - id: "{{ enis.results.0.interface.id }}"
            - id: "{{ enis.results.1.interface.id }}"
        instance_type: "{{ ec2_instance_type }}"
        wait: true
      register: create_with_eni
      check_mode: true
    
    - assert:
        that:
          - create_with_eni is changed
    
    - name: "Gather instance info"
      ec2_instance_info:
        filters:
          "tag:Name": "{{ ec2_name }}"
          instance-state-name: running
      register: _instances_info
    
    - assert:
        that:
          - _instances_info.instances | length == 1
          - _instances_info.instances.0.network_interfaces | length == 1

Expected Results

module should not attach interface to the instance

Actual Results

module attach the network interface to the instance

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 has_pr module module labels Mar 31, 2023
@abikouo abikouo closed this as completed Apr 7, 2023
@abikouo abikouo reopened this Apr 7, 2023
@abikouo abikouo removed needs_triage module module WIP Work in progress labels Apr 7, 2023
@abikouo abikouo closed this as completed Apr 7, 2023
@abikouo abikouo reopened this Apr 7, 2023
softwarefactory-project-zuul bot pushed a commit that referenced this issue May 30, 2023
…1576)

ec2_instance - fix idempotency issue when attaching ENI to isntance

SUMMARY

closes #1403

ISSUE TYPE


Bugfix Pull Request

COMPONENT NAME

ec2_instance

Reviewed-by: Alina Buzachis
patchback bot pushed a commit that referenced this issue May 30, 2023
…1576)

ec2_instance - fix idempotency issue when attaching ENI to isntance

SUMMARY

closes #1403

ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME

ec2_instance

Reviewed-by: Alina Buzachis
(cherry picked from commit b7533c5)
alinabuzachis pushed a commit to alinabuzachis/amazon.aws that referenced this issue Jun 1, 2023
…nsible-collections#1576)

ec2_instance - fix idempotency issue when attaching ENI to isntance

SUMMARY

closes ansible-collections#1403

ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME

ec2_instance

Reviewed-by: Alina Buzachis
(cherry picked from commit b7533c5)
softwarefactory-project-zuul bot pushed a commit that referenced this issue Jun 5, 2023
…1576) (#1579)

[PR #1576/b7533c55 backport][stable-6] ec2_instance - fix idempotency issue when attaching ENI to isntance

This is a backport of PR #1576 as merged into main (b7533c5).
SUMMARY

closes #1403

ISSUE TYPE


Bugfix Pull Request

COMPONENT NAME

ec2_instance

Reviewed-by: Alina Buzachis
softwarefactory-project-zuul bot pushed a commit that referenced this issue Jun 5, 2023
…1576) (#1588)

[manual backport stable-5] Fix: ec2_instance idempotency issue when attaching ENI to isntance (#1576)

ec2_instance - fix idempotency issue when attaching ENI to isntance
SUMMARY
closes #1403
ISSUE TYPE
Bugfix Pull Request
COMPONENT NAME
ec2_instance
Reviewed-by: Alina Buzachis
(cherry picked from commit b7533c5)
SUMMARY


ISSUE TYPE


Bugfix Pull Request
Docs Pull Request
Feature Pull Request
New Module Pull Request

COMPONENT NAME

ADDITIONAL INFORMATION

Reviewed-by: Bikouo Aubin
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 has_pr
Projects
None yet
2 participants