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 updates exisitng instances instead of creating new #526

Closed
1 task done
poleszcz opened this issue Oct 4, 2021 · 8 comments · Fixed by #529
Closed
1 task done

ec2_instance updates exisitng instances instead of creating new #526

poleszcz opened this issue Oct 4, 2021 · 8 comments · Fixed by #529
Labels
bug This issue/PR relates to a bug has_pr module module plugins plugin (any type) waiting_on_contributor Needs help. Feel free to engage to get things unblocked

Comments

@poleszcz
Copy link

poleszcz commented Oct 4, 2021

Summary

I'm using amazon.aws 2.0. I want to create new instance with module ec2_instance but instead ansible is updating other instances that use the same image. Apparently I'm missing something. Based on documentation I don't see how module is deciding to update or create new instance.

Collection Version


amazon.aws 2.0.0

- name: Create EC2 instance
  amazon.aws.ec2_instance:
    key_name: "{{ aws_ssh_key_name }}-{{ env_timestamp }}"
    region: "{{ region }}"
    instance_type: "{{ instance_type }}"
    image_id: "{{ ami }}"
    wait: yes
    wait_timeout: 600
    tags:
      Name: "{{ ec2_instance_name }}-{{ env_timestamp }}"
      Creator: "{{ creator }}"
      project: "{{ project }}"
    vpc_subnet_id: "{{ subnet_id }}"
    network:
      assign_public_ip: yes
      groups:
        - "{{ security_group.group_name }}"
  register: ec2

Issue Type

Bug Report

Component Name

ec2_instance

Ansible Version

ansible [core 2.11.3] 
  config file = None
  configured module search path = ['/Users/XXX/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /Users/XXX/Library/Python/3.8/lib/python/site-packages/ansible
  ansible collection location = /Users/XXX/.ansible/collections:/usr/share/ansible/collections
  executable location = /Users/XXX/Library/Python/3.8/bin/ansible
  python version = 3.8.2 (default, Apr  8 2021, 23:19:18) [Clang 12.0.5 (clang-1205.0.22.9)]
  jinja version = 3.0.1
  libyaml = False

Collection Versions

Collection       Version
---------------- -------
amazon.aws       2.0.0  
community.docker 1.9.1  

AWS SDK versions

WARNING: Package(s) not found: boto
Name: boto3
Version: 1.17.112
Summary: The AWS SDK for Python
Home-page: https://github.com/boto/boto3
Author: Amazon Web Services
Author-email: None
License: Apache License 2.0
Location: /Users/XXX/Library/Python/3.8/lib/python/site-packages
Requires: jmespath, botocore, s3transfer
Required-by: 
---
Name: botocore
Version: 1.20.112
Summary: Low-level, data-driven core of boto 3.
Home-page: https://github.com/boto/botocore
Author: Amazon Web Services
Author-email: None
License: Apache License 2.0
Location: /Users/XXX/Library/Python/3.8/lib/python/site-packages
Requires: jmespath, urllib3, python-dateutil
Required-by: s3transfer, boto3

Configuration

$ ansible-config dump --only-changed

OS / Environment

local: MacOS

Steps to Reproduce

I have few preexisting instances and they are getting updated and new instance is not created.

Expected Results

I exepect to get new instance created.

Actual Results

ec2_instance returns list of 6 updated 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) labels Oct 4, 2021
@goneri
Copy link
Member

goneri commented Oct 5, 2021

Hi @poleszcz,

Thank you for opening this. There is no top level name parameter, can you retry with one?

@goneri goneri added waiting_on_contributor Needs help. Feel free to engage to get things unblocked and removed needs_triage labels Oct 5, 2021
tremble added a commit to tremble/amazon.aws that referenced this issue Oct 7, 2021
@tremble
Copy link
Contributor

tremble commented Oct 7, 2021

@poleszcz The documentation currently says (under 'filters')

      - By default, instances are filtered for counting by their "Name" tag, base AMI, state (running, by default), and
        subnet ID.

What's slightly confusing here is that currently the 'Name' tag that it compares is only read from the name parameter, rather that also looking at the 'Name' key in the tags parameter.

@tremble tremble removed the waiting_on_contributor Needs help. Feel free to engage to get things unblocked label Oct 7, 2021
@ansibullbot ansibullbot added the waiting_on_contributor Needs help. Feel free to engage to get things unblocked label Oct 7, 2021
@poleszcz
Copy link
Author

@goneri Thanks for the hint - top level parameter "name" does the job.
The main sources of confusion are:

  1. Legacy doc under https://docs.ansible.com/ansible/latest/collections/amazon/aws (only ec2 and no ec2_instance)
  2. So in fact I'm using community.aws doc while declaring amazon.aws in the playbook
  3. Community doc used a confusing wording for top level name parameter - "The Name tag for the instance." (so why not to use Name under tags ;-) )
    Thanks once more.

@tremble
Copy link
Contributor

tremble commented Oct 12, 2021

(1) Will be updated when release 2.0.0 of this collection is a part of the latest version of Ansible
(2) See (1). In general you can expect modules to slowly migrate from community.aws over into amazon.aws as they're cleaned up and made 'supportable'. I think this would be a really good thing to raise with the documentation team over on ansible/ansible. Unfortunately as a collection we have no direct control over this.
(3) I agree, this will hopefully be fixed with release 2.1.0 of this collection.

ansible-zuul bot pushed a commit that referenced this issue Oct 12, 2021
…meter if no name and no filter provided (#529)

ec2_instance When searching for instances fall back to tag(Name) parameter if no name and no filter provided

SUMMARY
Reported in #526
When the name parameter isn't set but the Name tag is set the Name tag is ignored when searching for existing instances.
The documentation states:
- By default, instances are filtered for counting by their "Name" tag, base AMI, state (running, by default), and
  subnet ID.

As such I think we should consider this a bug.
ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME
ec2_instance
ADDITIONAL INFORMATION
fixes: #526

Reviewed-by: Alina Buzachis <None>
Reviewed-by: None <None>
fotto pushed a commit to fotto/amazon.aws that referenced this issue Jan 10, 2022
…ns#526)

* ec2_instance exception handling and client cleanup

Catch botocore and client errors on all API calls
Pass boto client to functions, rather than creating new clients throughout the code

* Add review suggestion to plugins/modules/ec2_instance.py

Co-authored-by: Mark Chappell <[email protected]>
abikouo pushed a commit to abikouo/amazon.aws that referenced this issue Sep 18, 2023
…ns#526)

* ec2_instance exception handling and client cleanup

Catch botocore and client errors on all API calls
Pass boto client to functions, rather than creating new clients throughout the code

* Add review suggestion to plugins/modules/ec2_instance.py

Co-authored-by: Mark Chappell <[email protected]>
abikouo pushed a commit to abikouo/amazon.aws that referenced this issue Sep 18, 2023
…ns#526)

* ec2_instance exception handling and client cleanup

Catch botocore and client errors on all API calls
Pass boto client to functions, rather than creating new clients throughout the code

* Add review suggestion to plugins/modules/ec2_instance.py

Co-authored-by: Mark Chappell <[email protected]>
abikouo pushed a commit to abikouo/amazon.aws that referenced this issue Oct 24, 2023
…ns#526)

* ec2_instance exception handling and client cleanup

Catch botocore and client errors on all API calls
Pass boto client to functions, rather than creating new clients throughout the code

* Add review suggestion to plugins/modules/ec2_instance.py

Co-authored-by: Mark Chappell <[email protected]>
@vanga
Copy link

vanga commented Feb 14, 2024

In my case, both community.aws and amazon.aws are installed and is misbehaving where even after specifying count, it was selecting existing instances also in addition to launching a new one. Specifying amazon.aws.ec2_instance instead of simply ec2_instance solved the issue.

@nickheyer
Copy link

This is clearly still an issue and the documentation is terrible. You'd expect more from a project like this.

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 module module plugins plugin (any type) waiting_on_contributor Needs help. Feel free to engage to get things unblocked
Projects
None yet
6 participants