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
Update inventory cache fix + tests #38229
Conversation
29b9f9d
to
5806530
Compare
10edafb
to
97f77c4
Compare
97f77c4
to
27fdd75
Compare
The changes to lib/ansible/plugins/inventory/aws_ec2.py should be cherry-picked to 2.5. |
27fdd75
to
28bfd18
Compare
2519cd6
to
143e7df
Compare
- name: write inventory config file | ||
copy: | ||
dest: ../test.aws_ec2.yml | ||
content: | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be a template! I'm all for the occasional use of copy with content but this is a little extreme!
prefix: 'security_groups' | ||
- key: 'tags' | ||
prefix: 'tag' | ||
# why no work |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because region
is not returned by DescribeInstances
.
This works though:
- key: 'placement.availability_zone[:-1]'
prefix: aws_region
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm. Maybe it would be good to include a "virtual key" or something that would pull out the region automatically and put it under placement
so users could have a placement.region
without needing to know quite as much Python.
# is terminated those attributes no longer exist, but others may: | ||
# if an instance-state-name filter has not been specified, find the running instances | ||
if not any([f['Name'] == 'instance-state-name' for f in filters]): | ||
filters.append({'Name': 'instance-state-name', 'Values': ['running']}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure we want to assume running. I can see never collecting terminated/shutting-down instances because instances in those states will never be available https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-lifecycle.html
I think a better default would be to collect pending/running/stopping/stopped hosts, since all of those may become available during a play, or have host vars that are needed.
vars: | ||
images: | ||
us-east-1: ami-4fffc834 | ||
us-east-2: ami-ea87a78f |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be done region-independently with ec2_ami_facts
. For CentOS I have a canned task:
- ec2_ami_facts:
# https://wiki.centos.org/Cloud/AWS collected 2018-01-10
filters:
architecture: x86_64
product-code: aw0evgkw8e5c1q413zgy5pjce
virtualization-type: hvm
root-device-type: ebs
name: 'CentOS Linux 7*'
ca64876
to
8f70fe6
Compare
…up, and finding an image for the host Create a separate playbook for removing the resources
9881d1c
to
0d7b36b
Compare
* Fix setting the cache when refresh_cache or --flush-cache are used * Use jsonify function that handles datetime objects in jsonfile cache plugin * Don't access self._options directly * Add initial integration tests for aws_ec2 inventory plugin * Add CI alias * Fix and add a few more unit tests * Add integration tests for constructed * Fix typo * Use inventory config templates * Collect all instances that are not terminated by default * Create separate playbook for setting up the VPC, subnet, security group, and finding an image for the host Create a separate playbook for removing the resources * Allow easier grouping by region and add an example * use a unified json encode/decode that can handle unsafe and vault
* Fix setting the cache when refresh_cache or --flush-cache are used * Use jsonify function that handles datetime objects in jsonfile cache plugin * Don't access self._options directly * Add initial integration tests for aws_ec2 inventory plugin * Add CI alias * Fix and add a few more unit tests * Add integration tests for constructed * Fix typo * Use inventory config templates * Collect all instances that are not terminated by default * Create separate playbook for setting up the VPC, subnet, security group, and finding an image for the host Create a separate playbook for removing the resources * Allow easier grouping by region and add an example * use a unified json encode/decode that can handle unsafe and vault
SUMMARY
#37689 should be resolved first and I will rebase.<- Done.ISSUE TYPE
COMPONENT NAME
aws_ec2
ANSIBLE VERSION