-
Notifications
You must be signed in to change notification settings - Fork 23.7k
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_vpc_route_table: Update matching_count parsing on find_subnets fu… #38707
Conversation
The test
|
@@ -294,7 +294,7 @@ def find_subnets(connection, module, vpc_id, identified_subnets): | |||
module.fail_json_aws(e, msg="Couldn't find subnet with names %s" % subnet_names) | |||
|
|||
for name in subnet_names: | |||
matching_count = len([1 for s in subnets_by_name if s.tags.get('Name') == name]) | |||
matching_count = len([1 for s in subnets_by_name if s['Tags'][0].get('Value') == name]) |
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.
How could this happen? I clearly stuffed this bit up in the boto3 conversion and no-one noticed.
I don't think this improvement will work unless the first tag is always the Name tag, which seems unlikely.
This should probably be
matching_count = len([1 for s in subnets_by_name for t in s.get('Tags', []) if t['Name'] == 'Name' and t['Value'] == name])
Could you add a test for this situation into test/integration/targets/ec2_vpc_route_table/tasks/main.yml (tests would hopefully have caught both the original error and the flaw in this solution)
Indeed I missed something @willthames! I added the tests and corrected a bug with the ternary operator used to give an appropriate subnet name: {
"assign_ipv6_address_on_creation": false,
"availability_zone": "us-east-1b",
"available_ip_address_count": 251,
"cidr_block": "10.228.231.0/24",
"default_for_az": false,
"id": "subnet-b92fce97",
"ipv6_cidr_block_association_set": [],
"map_public_ip_on_launch": false,
"state": "available",
"subnet_id": "subnet-b92fce97",
"tags": {
"Name": "public-b",
"Public": "False"
},
"vpc_id": "vpc-45a0ec3e"
}, |
Hm. The ternary operator without explicit bool is working exactly the same as with the bool for me. Looks good though. This should be backported to 2.5 as well. |
ansible#38707) * ec2_vpc_route_table: Update matching_count parsing on find_subnets function and tests * ec2_vpc_route_table: Update matching_count parsing on find_subnets function (cherry picked from commit 1905a6e)
ansible#38707) * ec2_vpc_route_table: Update matching_count parsing on find_subnets function and tests * ec2_vpc_route_table: Update matching_count parsing on find_subnets function
ansible#38707) * ec2_vpc_route_table: Update matching_count parsing on find_subnets function and tests * ec2_vpc_route_table: Update matching_count parsing on find_subnets function
ansible#38707) * ec2_vpc_route_table: Update matching_count parsing on find_subnets function and tests * ec2_vpc_route_table: Update matching_count parsing on find_subnets function
ansible#38707) * ec2_vpc_route_table: Update matching_count parsing on find_subnets function and tests * ec2_vpc_route_table: Update matching_count parsing on find_subnets function
ansible#38707) * ec2_vpc_route_table: Update matching_count parsing on find_subnets function and tests * ec2_vpc_route_table: Update matching_count parsing on find_subnets function
ansible#38707) * ec2_vpc_route_table: Update matching_count parsing on find_subnets function and tests * ec2_vpc_route_table: Update matching_count parsing on find_subnets function
ansible#38707) * ec2_vpc_route_table: Update matching_count parsing on find_subnets function and tests * ec2_vpc_route_table: Update matching_count parsing on find_subnets function
…nction. Fix #38570
SUMMARY
Fix #38570. Tags for the list of subnets are now parsed properly. I was able to reproduce the initial issue and this PR fixed it.
I don't understand how this could have worked initially if someone can shed some light on this I would appreciate.
ISSUE TYPE
COMPONENT NAME
ec2_vpc_route_table
ANSIBLE VERSION
ADDITIONAL INFORMATION
Also fixed a typo in the function comment.