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

Make ec2_instance able to create new instance or fail if instance matching filter already found #53610

Closed
Elias481 opened this issue Mar 10, 2019 · 10 comments
Labels
affects_2.8 This issue/PR affects Ansible v2.8 aws bot_closed cloud collection:community.aws collection Related to Ansible Collections work feature This issue/PR relates to a feature request. module This issue/PR relates to a module. needs_collection_redirect https://github.com/ansible/ansibullbot/blob/master/docs/collection_migration.md support:community This issue/PR relates to code supported by the Ansible community.

Comments

@Elias481
Copy link

SUMMARY

It would be fine if the filter in ec2_instance could be used to create new instance if no instance found matching filter criteria and fail otherwise without touching an already running instance.

ISSUE TYPE
  • Feature Idea
COMPONENT NAME

ec2_instance

ADDITIONAL INFORMATION
@ansibot
Copy link
Contributor

ansibot commented Mar 10, 2019

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

@ansibot
Copy link
Contributor

ansibot commented Mar 10, 2019

@ansibot
Copy link
Contributor

ansibot commented Mar 10, 2019

@Elias481, just so you are aware we have a dedicated Working Group for aws.
You can find other people interested in this in #ansible-aws on Freenode IRC
For more information about communities, meetings and agendas see https://github.com/ansible/community

click here for bot help

@ansibot ansibot added affects_2.8 This issue/PR affects Ansible v2.8 aws cloud feature This issue/PR relates to a feature request. module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. support:community This issue/PR relates to code supported by the Ansible community. labels Mar 10, 2019
@Shaps
Copy link
Contributor

Shaps commented Apr 28, 2019

@Elias481, thanks for submitting this, I don't think this should be included in the module itself, the module ( and ansible in general ) is to ensure you have the resource/s in the desired state; That said, if this is a feature you need, you can already achieve it by using ec2_instance_facts/failed_when:

- name: Fail if instance already exist
  ec2_instance_facts:
    [...]
    filters:
      <your_filters>
  register: instance_exists
  failed_when: instance_exists.instances | length > 0

@ansibot ansibot removed the needs_triage Needs a first human triage before being processed. label Apr 28, 2019
@Elias481
Copy link
Author

Elias481 commented May 5, 2019

Yes for sure it's possible to check the in yet another additional ansible block.
Its just that I think the use-case is quite common. For setup of new servers an instance is created, according to specs.
During lifetime it's most often not the case that adjuments to the instance would be done with involving ansible and also it's difficult to ensure that the changes are always populated to ansible config.

It is always the case and the approach is symply to say users (acting as admins) that all changes that they do to the system without commiting it to ansible will be overwritten.
While this can be quite safely handled or at least leads to only partly rolled-back changes with (hopefully) learning effect, it's very dangerous to apply changed settings to an instance by mistake with next ansible run because that is likely to cause an uncoordinated reboot of the instance.

For me it's a legitimate definition of having a desired state "instance running" that I just want to ensure the instance is available before continuing the play with the parts that follow which need the instance to be running and having the definition of the details only applied if instance does not exists.

So I do not really want to fail, but just an option that tells the module to not change anything if the instance is already there and populate the results with the found instance.

Of cause an instance_facts step before can be used. But it's not only quite much overhead of ansible script lines (which is anyway very much to implement sane workflows) but also avoids a call to gather-instance-facts for new instances (as the ec2_instance module is querying the same again).

@resmo
Copy link
Contributor

resmo commented May 8, 2019

Looking at other cloud modules (vultr, cloustack, cloudscale) there is a logic to not changing a running instance if the change would require a reboot unless force=true is given.

https://docs.ansible.com/ansible/latest/modules/vultr_server_module.html#parameters

@Shaps
Copy link
Contributor

Shaps commented May 10, 2019

@resmo sensible comment, I like consistency, so I'm happy to add the force parameter to the module. That said, I'd set it to true by default to not drastically change the module's behavior. Thoughts?

@resmo
Copy link
Contributor

resmo commented May 10, 2019

@Shaps for "backwards compatibility" it make sense to set it to "true".

@ansibot
Copy link
Contributor

ansibot commented Feb 1, 2020

@ansibot ansibot added collection Related to Ansible Collections work collection:community.aws needs_collection_redirect https://github.com/ansible/ansibullbot/blob/master/docs/collection_migration.md labels Apr 29, 2020
@ansibot
Copy link
Contributor

ansibot commented Aug 16, 2020

Thank you very much for your interest in Ansible. Ansible has migrated much of the content into separate repositories to allow for more rapid, independent development. We are closing this issue/PR because this content has been moved to one or more collection repositories.

For further information, please see:
https://github.com/ansible/ansibullbot/blob/master/docs/collection_migration.md

@ansibot ansibot closed this as completed Aug 16, 2020
@ansible ansible locked and limited conversation to collaborators Sep 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.8 This issue/PR affects Ansible v2.8 aws bot_closed cloud collection:community.aws collection Related to Ansible Collections work feature This issue/PR relates to a feature request. module This issue/PR relates to a module. needs_collection_redirect https://github.com/ansible/ansibullbot/blob/master/docs/collection_migration.md support:community This issue/PR relates to code supported by the Ansible community.
Projects
None yet
Development

No branches or pull requests

4 participants