-
Notifications
You must be signed in to change notification settings - Fork 397
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
adding uptime parameter to community.aws.ec2_instance_info #316
Conversation
adding uptime parameter to ec2_instance_info.py based on older Ansible 2.3 module written by James Laska ec2_instance_find.py that does not appear to be in the upstream anywhere, so this feature was lost in time.
adding additional information to the task desciption int he exampel
minor mistake, I had minutes instead of hours, the int is in hours
Thanks for this. I agree this kind of functionality would be nice. I have a couple questions/concerns about the new parameter.
Maybe @jillr could jump in? |
So the launch time that AWS returns gets reset if you stop and restart the instance. I did a bunch of testing to see that particular parameter. So specifically from this list of filters-> https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeInstances.html The
I just copied the idea from the original module, so I don't really have an opinion here. Minutes is fine since you get more granular... but I chose hours b/c you get charged per hours, and usually workshops, QE, etc are all done in hours (it takes about an hour to test all 5 instances). So totally flexible here.
Yeah but its the same problem if you just push the logic to the Ansible Playbook, system clock time is always going to be a problem, but we tested it from a variety of random work stations and it is consistently seems to get us the results we need. Having this complexity in the module makes much more sense than an insanely complicated Ansible Playbook. The use case allows really clean multi-region Ansible Job Templates in the workflow visualizer to clean up regions on specified policy-> |
* Sanity test / doc-default-does-not-match-spec fixups * General docs cleanup
Ah, didn't realize the launch time gets reset. Good to know. What I'm suggesting with time difference is to retain the functionality you are providing, but shift a few things around in the code. As it stands this will opt every playbook using this module into using the uptime filter. So instead of setting the time delta to 0 if if uptime:
timedelta = int(uptime)
...
instances = [instance for instance in instances if ...<time filter>] |
* import order * Add retry decorators * Switch tests to using module_defaults * module_defaults * Add initial _info tests * Handle Boto Errors with fail_json_aws * Test state=absent when IGW missing * Support not purging tags * Support converting Tags from boto to dict * Add tagging tests * Use random CIDR for VPC * Add check_mode tests * changelog
…andle AWS rate limiting (#324) * Add jittered_backoff to handle AWS rate limiting * Fix for failing test * Add changelog fragment
* Explicitly pass the subnet the instance should live on - try to avoid https://github.com/ansible-collections/community.aws/issues/329 * Make sure we delete the Instance (and free the EIP) before we try to drop the IGW * Use IDs when cleaning up EC2 instances
Also please make sure this functionality gets integration tests - thanks! |
as per @gravesm suggestion (hopefully) trying a different approach here
adding uptime parameter to ec2_instance_info.py based on older Ansible 2.3 module written by James Laska ec2_instance_find.py that does not appear to be in the upstream anywhere, so this feature was lost in time.
adding additional information to the task desciption int he exampel
minor mistake, I had minutes instead of hours, the int is in hours
as per @gravesm suggestion (hopefully) trying a different approach here
It looks like your merge has done something a little weird, so you're triggering additional tests. Rather than "git merge main" I'd strongly recommend using git rebase:
Atlassian have a nice description of what it is and how it works: |
changing to minutes per @gravesm 's suggestion
ok @tremble ... I think I did this correctly now.... (maybe....) now working on tests |
adding integration test per @jillr suggestion
i messed up this pull request, going to open a clean one |
SUMMARY
This parameter used to exist in the ec2_instance_find.py module that somehow got lost time written by James Laska. It is currently (before this PR) very difficult and not very Ansible freindly to determine how long an instance has been running, as the only filter provided is launch_time. It is a common cloud automation use-case to determine which instances have been online longer than a certain time period (e.g. which instances have been running for more than 2 hours?)
From experimentation and much Googling, the best I could come up with was something like this->
which is not easy to read, requires some Python knowledge and may be outside the skill set of an operations engineer who is writing Ansible Playbooks. Working with the infamous @Spredzy we have come up with a very simple
uptime
parameter based on the previous module, and merged this into the existing functionality of ec2_instance_info so we don't need to add "yet another AWS module" to the infinite queue. We also made sure this works for both python 2 and python 3 environments.ISSUE TYPE
COMPONENT NAME
ec2_instance_info
ADDITIONAL INFORMATION
Here is an example