Add option to group ec2 instances by platform. (#27848)

All credits to https://github.com/felipecvo

See PR: https://github.com/ansible/ansible/pull/14246
This commit is contained in:
Sebastian Cruz 2017-08-07 19:45:04 +01:00 committed by Chris Alfonso
parent 1fe14da226
commit ce5e4dfc38
2 changed files with 11 additions and 0 deletions

View file

@ -135,6 +135,7 @@ group_by_aws_account = False
group_by_ami_id = True
group_by_instance_type = True
group_by_instance_state = False
group_by_platform = True
group_by_key_pair = True
group_by_vpc_id = True
group_by_security_group = True

View file

@ -930,6 +930,16 @@ class Ec2Inventory(object):
if self.nested_groups:
self.push_group(self.inventory, 'instance_states', state_name)
# Inventory: Group by platform
if self.group_by_platform:
if instance.platform:
platform = self.to_safe('platform_' + instance.platform)
else:
platform = self.to_safe('platform_undefined')
self.push(self.inventory, platform, hostname)
if self.nested_groups:
self.push_group(self.inventory, 'platforms', platform)
# Inventory: Group by key pair
if self.group_by_key_pair and instance.key_name:
key_name = self.to_safe('key_' + instance.key_name)