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: fix to handle create instance in specified AZ #1150

Conversation

mandar242
Copy link
Contributor

SUMMARY

This PR adds a fix to allow launching an instance in specified AZ when vpc_subnet_id is not specified.
The current code does not consider the AZ and launches the instance in default subnet of default vpc for the specified region.
https://github.com/ansible-collections/amazon.aws/blob/main/plugins/modules/ec2_instance.py#L1584-L1593

Fixes #1120

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

ec2_instance

ADDITIONAL INFORMATION

Without the fix, the below playbook will launch instance in default subnet ignoring specified AZ.
Example Playbook to launch instance in us-west-2b AZ.

---
- name: Spin up ec2 instance
  hosts: localhost
  gather_facts: false
  tasks:
    - name: Launch regular ec2 instances in us-west-1b
      amazon.aws.ec2_instance:
        name: "test-instance-us-west-1b"
        instance_type: t2.micro
        image_id: ami-xxxxx
        state: present
        availability_zone: us-west-1b
        region: us-west-1
        tags:
          terminate-this: yes
        network:
          assign_public_ip: yes
      register: create_result

    - ec2_instance_info:
        instance_ids:
          - "{{ create_result.instance_ids[0] }}"
        region: us-west-1
      register: info_result
    - assert:
        that: info_result.instances[0].placement.availability_zone == 'us-west-1b'

@ansibullbot
Copy link

@ansibullbot ansibullbot added bug This issue/PR relates to a bug community_review module module needs_triage plugins plugin (any type) small_patch Hopefully easy to review labels Oct 10, 2022
@softwarefactory-project-zuul

This comment was marked as outdated.

@ansibullbot ansibullbot added integration tests/integration tests tests and removed small_patch Hopefully easy to review labels Oct 10, 2022
@softwarefactory-project-zuul
Copy link
Contributor

Build succeeded.

✔️ ansible-galaxy-importer SUCCESS in 4m 26s
✔️ build-ansible-collection SUCCESS in 5m 01s
✔️ ansible-test-sanity-aws-ansible-python38 SUCCESS in 10m 01s
✔️ ansible-test-sanity-aws-ansible-2.12-python38 SUCCESS in 10m 08s
✔️ ansible-test-sanity-aws-ansible-2.13-python38 SUCCESS in 10m 24s
✔️ ansible-test-units-amazon-aws-python36 SUCCESS in 7m 49s
✔️ ansible-test-units-amazon-aws-python38 SUCCESS in 7m 26s
✔️ ansible-test-units-amazon-aws-python39 SUCCESS in 6m 03s
✔️ cloud-tox-py3 SUCCESS in 3m 30s
✔️ ansible-test-splitter SUCCESS in 2m 30s
✔️ integration-amazon.aws-1 SUCCESS in 43m 12s
✔️ integration-amazon.aws-2 SUCCESS in 31m 57s
✔️ integration-amazon.aws-3 SUCCESS in 34m 56s
⚠️ integration-amazon.aws-4 SKIPPED
⚠️ integration-amazon.aws-5 SKIPPED
⚠️ integration-amazon.aws-6 SKIPPED
⚠️ integration-amazon.aws-7 SKIPPED
⚠️ integration-amazon.aws-8 SKIPPED
⚠️ integration-amazon.aws-9 SKIPPED
⚠️ integration-amazon.aws-10 SKIPPED
⚠️ integration-amazon.aws-11 SKIPPED
⚠️ integration-amazon.aws-12 SKIPPED
⚠️ integration-amazon.aws-13 SKIPPED
⚠️ integration-amazon.aws-14 SKIPPED
⚠️ integration-amazon.aws-15 SKIPPED
⚠️ integration-amazon.aws-16 SKIPPED
⚠️ integration-amazon.aws-17 SKIPPED
⚠️ integration-amazon.aws-18 SKIPPED
✔️ integration-community.aws-1 SUCCESS in 7m 44s
⚠️ integration-community.aws-2 SKIPPED
⚠️ integration-community.aws-3 SKIPPED
⚠️ integration-community.aws-4 SKIPPED
⚠️ integration-community.aws-5 SKIPPED
⚠️ integration-community.aws-6 SKIPPED
⚠️ integration-community.aws-7 SKIPPED
⚠️ integration-community.aws-8 SKIPPED
⚠️ integration-community.aws-9 SKIPPED
⚠️ integration-community.aws-10 SKIPPED
⚠️ integration-community.aws-11 SKIPPED
⚠️ integration-community.aws-12 SKIPPED
⚠️ integration-community.aws-13 SKIPPED
⚠️ integration-community.aws-14 SKIPPED
⚠️ integration-community.aws-15 SKIPPED
⚠️ integration-community.aws-16 SKIPPED
⚠️ integration-community.aws-17 SKIPPED
⚠️ integration-community.aws-18 SKIPPED
✔️ ansible-test-changelog SUCCESS in 2m 15s

@goneri goneri added the mergeit Merge the PR (SoftwareFactory) label Oct 11, 2022
@softwarefactory-project-zuul
Copy link
Contributor

Build succeeded (gate pipeline).

✔️ ansible-galaxy-importer SUCCESS in 4m 51s
✔️ build-ansible-collection SUCCESS in 5m 57s
✔️ ansible-test-sanity-aws-ansible-python38 SUCCESS in 11m 03s
✔️ ansible-test-sanity-aws-ansible-2.12-python38 SUCCESS in 9m 42s
✔️ ansible-test-sanity-aws-ansible-2.13-python38 SUCCESS in 9m 18s
✔️ ansible-test-units-amazon-aws-python36 SUCCESS in 7m 36s
✔️ ansible-test-units-amazon-aws-python38 SUCCESS in 8m 40s
✔️ ansible-test-units-amazon-aws-python39 SUCCESS in 6m 45s
✔️ cloud-tox-py3 SUCCESS in 4m 20s
✔️ ansible-test-splitter SUCCESS in 3m 33s
✔️ integration-amazon.aws-1 SUCCESS in 45m 20s
✔️ integration-amazon.aws-2 SUCCESS in 34m 37s
✔️ integration-amazon.aws-3 SUCCESS in 31m 08s
⚠️ integration-amazon.aws-4 SKIPPED
⚠️ integration-amazon.aws-5 SKIPPED
⚠️ integration-amazon.aws-6 SKIPPED
⚠️ integration-amazon.aws-7 SKIPPED
⚠️ integration-amazon.aws-8 SKIPPED
⚠️ integration-amazon.aws-9 SKIPPED
⚠️ integration-amazon.aws-10 SKIPPED
⚠️ integration-amazon.aws-11 SKIPPED
⚠️ integration-amazon.aws-12 SKIPPED
⚠️ integration-amazon.aws-13 SKIPPED
⚠️ integration-amazon.aws-14 SKIPPED
⚠️ integration-amazon.aws-15 SKIPPED
⚠️ integration-amazon.aws-16 SKIPPED
⚠️ integration-amazon.aws-17 SKIPPED
⚠️ integration-amazon.aws-18 SKIPPED
✔️ integration-community.aws-1 SUCCESS in 9m 00s
⚠️ integration-community.aws-2 SKIPPED
⚠️ integration-community.aws-3 SKIPPED
⚠️ integration-community.aws-4 SKIPPED
⚠️ integration-community.aws-5 SKIPPED
⚠️ integration-community.aws-6 SKIPPED
⚠️ integration-community.aws-7 SKIPPED
⚠️ integration-community.aws-8 SKIPPED
⚠️ integration-community.aws-9 SKIPPED
⚠️ integration-community.aws-10 SKIPPED
⚠️ integration-community.aws-11 SKIPPED
⚠️ integration-community.aws-12 SKIPPED
⚠️ integration-community.aws-13 SKIPPED
⚠️ integration-community.aws-14 SKIPPED
⚠️ integration-community.aws-15 SKIPPED
⚠️ integration-community.aws-16 SKIPPED
⚠️ integration-community.aws-17 SKIPPED
⚠️ integration-community.aws-18 SKIPPED
✔️ ansible-test-changelog SUCCESS in 2m 45s

@softwarefactory-project-zuul softwarefactory-project-zuul bot merged commit 395d4fd into ansible-collections:main Oct 11, 2022
@tremble tremble added the backport-5 PR should be backported to the stable-5 branch label Oct 19, 2022
@patchback
Copy link

patchback bot commented Oct 19, 2022

Backport to stable-5: 💚 backport PR created

✅ Backport PR branch: patchback/backports/stable-5/395d4fda1ec549020d070d4465835166094e4777/pr-1150

Backported as #1184

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

patchback bot pushed a commit that referenced this pull request Oct 19, 2022
ec2_instance: fix to handle create instance in specified AZ

SUMMARY

This PR adds a fix to allow launching an instance in specified AZ when vpc_subnet_id is not specified.
The current code does not consider the AZ and launches the instance in default subnet of default vpc for the specified region.
https://github.com/ansible-collections/amazon.aws/blob/main/plugins/modules/ec2_instance.py#L1584-L1593

Fixes #1120
ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME

ec2_instance
ADDITIONAL INFORMATION

Without the fix, the below playbook will launch instance in default subnet ignoring specified AZ.
Example Playbook to launch instance in us-west-2b AZ.

---
- name: Spin up ec2 instance
  hosts: localhost
  gather_facts: false
  tasks:
    - name: Launch regular ec2 instances in us-west-1b
      amazon.aws.ec2_instance:
        name: "test-instance-us-west-1b"
        instance_type: t2.micro
        image_id: ami-xxxxx
        state: present
        availability_zone: us-west-1b
        region: us-west-1
        tags:
          terminate-this: yes
        network:
          assign_public_ip: yes
      register: create_result

    - ec2_instance_info:
        instance_ids:
          - "{{ create_result.instance_ids[0] }}"
        region: us-west-1
      register: info_result
    - assert:
        that: info_result.instances[0].placement.availability_zone == 'us-west-1b'

Reviewed-by: Mike Graves <mgraves@redhat.com>
Reviewed-by: Gonéri Le Bouder <goneri@lebouder.net>
(cherry picked from commit 395d4fd)
softwarefactory-project-zuul bot pushed a commit that referenced this pull request Oct 19, 2022
…1184)

[PR #1150/395d4fda backport][stable-5] ec2_instance: fix to handle create instance in specified AZ

This is a backport of PR #1150 as merged into main (395d4fd).
SUMMARY

This PR adds a fix to allow launching an instance in specified AZ when vpc_subnet_id is not specified.
The current code does not consider the AZ and launches the instance in default subnet of default vpc for the specified region.
https://github.com/ansible-collections/amazon.aws/blob/main/plugins/modules/ec2_instance.py#L1584-L1593

Fixes #1120
ISSUE TYPE


Bugfix Pull Request

COMPONENT NAME

ec2_instance
ADDITIONAL INFORMATION


Without the fix, the below playbook will launch instance in default subnet ignoring specified AZ.
Example Playbook to launch instance in us-west-2b AZ.

---
- name: Spin up ec2 instance
  hosts: localhost
  gather_facts: false
  tasks:
    - name: Launch regular ec2 instances in us-west-1b
      amazon.aws.ec2_instance:
        name: "test-instance-us-west-1b"
        instance_type: t2.micro
        image_id: ami-xxxxx
        state: present
        availability_zone: us-west-1b
        region: us-west-1
        tags:
          terminate-this: yes
        network:
          assign_public_ip: yes
      register: create_result

    - ec2_instance_info:
        instance_ids:
          - "{{ create_result.instance_ids[0] }}"
        region: us-west-1
      register: info_result
    - assert:
        that: info_result.instances[0].placement.availability_zone == 'us-west-1b'

Reviewed-by: Mark Chappell <None>
@mandar242 mandar242 deleted the ec2_instance_subnet_fix branch May 9, 2023 02:46
abikouo pushed a commit to abikouo/amazon.aws that referenced this pull request Sep 18, 2023
aws_secret - Support purge_tags

SUMMARY
aws_secret currently defaults to purging all tags (even if tags isn't specified), this is a little aggressive.

Add purge_tags parameter
Only purge tags if tags: {} is set (rather than when tags is None

ISSUE TYPE

Feature Pull Request

COMPONENT NAME
aws_secret
ADDITIONAL INFORMATION
Related to ansible-collections#1146

Reviewed-by: Markus Bergholz <git@osuv.de>
Reviewed-by: Mark Chappell <None>
Reviewed-by: Alina Buzachis <None>
abikouo pushed a commit to abikouo/amazon.aws that referenced this pull request Sep 18, 2023
aws_secret - Support purge_tags

SUMMARY
aws_secret currently defaults to purging all tags (even if tags isn't specified), this is a little aggressive.

Add purge_tags parameter
Only purge tags if tags: {} is set (rather than when tags is None

ISSUE TYPE

Feature Pull Request

COMPONENT NAME
aws_secret
ADDITIONAL INFORMATION
Related to ansible-collections#1146

Reviewed-by: Markus Bergholz <git@osuv.de>
Reviewed-by: Mark Chappell <None>
Reviewed-by: Alina Buzachis <None>
abikouo pushed a commit to abikouo/amazon.aws that referenced this pull request Oct 24, 2023
aws_secret - Support purge_tags

SUMMARY
aws_secret currently defaults to purging all tags (even if tags isn't specified), this is a little aggressive.

Add purge_tags parameter
Only purge tags if tags: {} is set (rather than when tags is None

ISSUE TYPE

Feature Pull Request

COMPONENT NAME
aws_secret
ADDITIONAL INFORMATION
Related to ansible-collections#1146

Reviewed-by: Markus Bergholz <git@osuv.de>
Reviewed-by: Mark Chappell <None>
Reviewed-by: Alina Buzachis <None>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-5 PR should be backported to the stable-5 branch bug This issue/PR relates to a bug community_review has_issue integration tests/integration mergeit Merge the PR (SoftwareFactory) module module plugins plugin (any type) tests tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create instance ignoring specified availability_zone
5 participants