summaryrefslogtreecommitdiffstats
path: root/bin/ansibleutil.py
diff options
context:
space:
mode:
authorKenny Woodson <kwoodson@redhat.com>2015-02-03 15:08:26 -0500
committerKenny Woodson <kwoodson@redhat.com>2015-02-03 15:08:26 -0500
commit6481ca629cc2bcf5bd9c7f15be14a77e57086514 (patch)
treebe8f5580f34630127ff83b5cfa9de1a31c1f3db9 /bin/ansibleutil.py
parentd3dee2db1c87b074075b3bbcbe8931862ee7eca3 (diff)
downloadopenshift-6481ca629cc2bcf5bd9c7f15be14a77e57086514.tar.gz
openshift-6481ca629cc2bcf5bd9c7f15be14a77e57086514.tar.bz2
openshift-6481ca629cc2bcf5bd9c7f15be14a77e57086514.tar.xz
openshift-6481ca629cc2bcf5bd9c7f15be14a77e57086514.zip
ossh script added for ssh meta query capabilities
Diffstat (limited to 'bin/ansibleutil.py')
-rw-r--r--bin/ansibleutil.py22
1 files changed, 13 insertions, 9 deletions
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