diff options
Diffstat (limited to 'inventory')
-rwxr-xr-x | inventory/multi_ec2.py | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/inventory/multi_ec2.py b/inventory/multi_ec2.py index 2cbf33473..23cf5ecf1 100755 --- a/inventory/multi_ec2.py +++ b/inventory/multi_ec2.py @@ -239,22 +239,33 @@ class MultiEc2(object): def apply_account_config(self, acc_config): ''' Apply account config settings ''' - if not acc_config.has_key('hostvars') and not acc_config.has_key('all_group'): - return - results = self.all_ec2_results[acc_config['name']] - # Update each hostvar with the newly desired key: value - for host_property, value in acc_config['hostvars'].items(): + + # Update each hostvar with the newly desired key: value + for new_var, value in acc_config.get('extra_vars', {}).items(): # Verify the account results look sane # by checking for these keys ('_meta' and 'hostvars' exist) if results.has_key('_meta') and results['_meta'].has_key('hostvars'): for data in results['_meta']['hostvars'].values(): - data[str(host_property)] = str(value) + data[str(new_var)] = str(value) # Add this group if results.has_key(acc_config['all_group']): - results["%s_%s" % (host_property, value)] = \ - copy.copy(results[acc_config['all_group']]) + results["%s_%s" % (new_var, value)] = \ + copy.copy(results[acc_config['all_group']]) + + # Clone groups goes here + for name_from, name_to in acc_config.get('clone_groups', {}).items(): + if results.has_key(name_from): + results[name_to] = copy.copy(results[name_from]) + + # Clone vars goes here + for to_name, from_name in acc_config.get('clone_vars', {}).items(): + # Verify the account results look sane + # by checking for these keys ('_meta' and 'hostvars' exist) + if results.has_key('_meta') and results['_meta'].has_key('hostvars'): + for data in results['_meta']['hostvars'].values(): + data[str(to_name)] = data.get(str(from_name), 'nil') # store the results back into all_ec2_results self.all_ec2_results[acc_config['name']] = results |