From ce5e4dfc381742751e035b25c94aff6085abaf5b Mon Sep 17 00:00:00 2001 From: Sebastian Cruz Date: Mon, 7 Aug 2017 19:45:04 +0100 Subject: [PATCH] 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 --- contrib/inventory/ec2.ini | 1 + contrib/inventory/ec2.py | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/contrib/inventory/ec2.ini b/contrib/inventory/ec2.ini index e11a69cc16a..ab1ad6222dc 100644 --- a/contrib/inventory/ec2.ini +++ b/contrib/inventory/ec2.ini @@ -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 diff --git a/contrib/inventory/ec2.py b/contrib/inventory/ec2.py index 16f52890b26..060c5e64243 100755 --- a/contrib/inventory/ec2.py +++ b/contrib/inventory/ec2.py @@ -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)