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

LAM-40 Add slaves host var, fix and test proxy_env var

parent 9655605a
---
- hosts: masters
user: root
tasks:
- name: install screen to master without proxy
apt: name=screen state=installed
tags: install
- hosts: slaves
user: root
tasks:
- name: install screen to slaves using proxy
apt: name=screen state=installed
environment: proxy_env
tags: install
......@@ -11,11 +11,11 @@ class Manager:
self.inventory = {}
self.host_vars = {}
for group in provisioner_response.keys():
if group == "masters":
self.master_fqdn = response[u'SNF:fqdn']
self.inventory[group] = {"hosts": []}
for response in provisioner_response[group]:
self.inventory[group]["hosts"].append(response[u'SNF:fqdn'])
if group == "masters":
self.master_fqdn = response[u'SNF:fqdn'].split('.')[0]
def create_inventory(self):
"""
......@@ -23,13 +23,15 @@ class Manager:
:return:
"""
inventory_groups = []
host_id = 1
for group in self.inventory.keys():
inventory_groups.append(ansible.inventory.group.Group(name=group))
if group != "masters":
self.host_vars["http_proxy"] = "http://"+self.master_fqdn+":3128"
self.host_vars["proxy_env"] = {"http_proxy": "http://"+self.master_fqdn+":3128"}
self.host_vars["id"] = host_id
host_id += 1
for host in self.inventory[group]["hosts"]:
ansible_host = ansible.inventory.host.Host(name=host)
host_vars = self.host_vars.iteritems()
for var_key, var_value in self.host_vars.iteritems():
ansible_host.set_variable(var_key, var_value)
inventory_groups[-1].add_host(ansible_host)
......@@ -55,6 +57,9 @@ class Manager:
if __name__ == "__main__":
manager = Manager()
manager = Manager(test_provisioner_response)
manager.create_inventory()
manager.run_playbook(playbook_file="../ansible/playbooks/test.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"])
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