Unverified Commit 453b491f authored by Ioannis Tsafaras's avatar Ioannis Tsafaras Committed by Avraam Tsantekidis
Browse files

LAM-40 WIP

parent d79ccbe6
...@@ -61,3 +61,4 @@ target/ ...@@ -61,3 +61,4 @@ target/
MANIFEST MANIFEST
old_kamaki old_kamaki
*.idea
...@@ -9,32 +9,43 @@ class Manager: ...@@ -9,32 +9,43 @@ class Manager:
def __init__(self, provisioner_response): def __init__(self, provisioner_response):
self.inventory = {} self.inventory = {}
self.host_vars = {}
for group in provisioner_response.keys(): for group in provisioner_response.keys():
self.inventory[group] = {"hosts": []} self.inventory[group] = {"hosts": []}
for response in provisioner_response[group]: for response in provisioner_response[group]:
self.inventory[group]["hosts"].append(response[u'SNF:fqdn']) self.inventory[group]["hosts"].append(response[u'SNF:fqdn'])
if group == "masters": if group == "master":
self.master_fqdn = response[u'SNF:fqdn'].split('.')[0] self.master_fqdn = response[u'SNF:fqdn'].split('.')[0]
def create_inventory(self): def create_inventory(self, private_ips):
""" """
Create the inventory using the ansible library objects Create the inventory using the ansible library objects
:return: :return:
""" """
inventory_groups = [] inventory_groups = []
host_id = 1 host_vars = {}
for group in self.inventory.keys():
inventory_groups.append(ansible.inventory.group.Group(name=group)) master_group = ansible.inventory.group.Group(name="master")
if group != "masters": host = self.inventory["master"]["hosts"][0]
self.host_vars["proxy_env"] = {"http_proxy": "http://"+self.master_fqdn+":3128"} ansible_host = ansible.inventory.host.Host(name=host)
self.host_vars["id"] = host_id host_vars["internal_ip"] = ipdict[host.split('.')[0]]
host_id += 1 for var_key, var_value in host_vars.iteritems():
for host in self.inventory[group]["hosts"]: ansible_host.set_variable(var_key, var_value)
ansible_host = ansible.inventory.host.Host(name=host) ansible_host.set_variable("id", 0)
for var_key, var_value in self.host_vars.iteritems(): master_group.add_host(ansible_host)
ansible_host.set_variable(var_key, var_value) inventory_groups.append(master_group)
inventory_groups[-1].add_host(ansible_host)
slave_group = ansible.inventory.group.Group(name="slaves")
host_vars["proxy_env"] = {"http_proxy": "http://"+self.master_fqdn+":3128"}
for host_id, host in enumerate(self.inventory["slaves"]["hosts"], start=1):
ansible_host = ansible.inventory.host.Host(name=host)
host_vars["internal_ip"] = ipdict[host.split('.')[0]]
for var_key, var_value in host_vars.iteritems():
ansible_host.set_variable(var_key, var_value)
ansible_host.set_variable("id", host_id)
slave_group.add_host(ansible_host)
inventory_groups.append(slave_group)
self.inventory = ansible.inventory.Inventory(host_list=None) self.inventory = ansible.inventory.Inventory(host_list=None)
for group in inventory_groups: for group in inventory_groups:
...@@ -42,7 +53,7 @@ class Manager: ...@@ -42,7 +53,7 @@ class Manager:
return self.inventory return self.inventory
def run_playbook(self, playbook_file, tags): def run_playbook(self, playbook_file, tags=None):
""" """
Run the playbook_file using created inventory and tags specified Run the playbook_file using created inventory and tags specified
:return: :return:
...@@ -58,8 +69,11 @@ class Manager: ...@@ -58,8 +69,11 @@ class Manager:
if __name__ == "__main__": if __name__ == "__main__":
from provisioner import Provisioner
provisioner = Provisioner("lambda")
inv = provisioner.create_lambda_cluster("test_vm")
manager = Manager(test_provisioner_response) manager = Manager(inv, provisioner)
manager.create_inventory() manager.create_inventory(provisioner.get_server_private_ip())
# manager.run_playbook(playbook_file="../../ansible/playbooks/testinventory.yml", tags=["touch"]) # manager.run_playbook(playbook_file="../../ansible/playbooks/testinventory.yml", tags=["touch"])
manager.run_playbook(playbook_file="../../ansible/playbooks/testproxy.yml", tags=["install"]) manager.run_playbook(playbook_file="../../ansible/playbooks/testproxy.yml", tags=["install"])
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment