From 6481ca629cc2bcf5bd9c7f15be14a77e57086514 Mon Sep 17 00:00:00 2001 From: Kenny Woodson Date: Tue, 3 Feb 2015 15:08:26 -0500 Subject: ossh script added for ssh meta query capabilities --- bin/ansibleutil.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'bin/ansibleutil.py') diff --git a/bin/ansibleutil.py b/bin/ansibleutil.py index a16a4dca9..26fb25493 100644 --- a/bin/ansibleutil.py +++ b/bin/ansibleutil.py @@ -22,8 +22,8 @@ class AnsibleUtil(object): if p.returncode != 0: raise RuntimeError(err) - with open('/tmp/ans.out','w') as fd: - fd.writelines(out) + #with open('/tmp/ans.out','w') as fd: + #fd.writelines(out) return json.loads(out.strip()) def get_environments(self): @@ -50,18 +50,22 @@ class AnsibleUtil(object): return groups - def get_host_address(self): - pattern = re.compile(r'^tag_Name_(.*)') + def build_host_dict(self): inv = self.get_inventory() - inst_names = {} - for key in inv.keys(): - m = pattern.match(key) - if m: inst_names[m.group(1)] = inv[key] + inst_by_env = {} + for dns, host in inv['_meta']['hostvars'].items(): + if host['ec2_tag_environment'] not in inst_by_env: + inst_by_env[host['ec2_tag_environment']] = {} + + #if inst_by_env[host['ec2_tag_environment']][host['ec2_tag_Name']]: + #raise Exception('Duplicate ec2_tag_Name found: %s' % host['ec2_tag_Name']) + host_id = "%s:%s" % (host['ec2_tag_Name'],host['ec2_id']) + inst_by_env[host['ec2_tag_environment']][host_id] = host - return inst_names + return inst_by_env -- cgit v1.2.3