Unverified Commit bd9f95f3 authored by Ioannis Tsafaras's avatar Ioannis Tsafaras Committed by Avraam Tsantekidis

Refactor creation of inventory. Now 'all' group and all variables work. Add...

Refactor creation of inventory. Now 'all' group and all variables work. Add line to http proxy config
parent db0ecb25
......@@ -15,3 +15,4 @@
apt: name=screen state=installed
environment: proxy_env
tags: install
......@@ -11,8 +11,8 @@
- name: Copy environment file.
copy: src=environment dest=/etc/environment backup=no owner=root group=root mode=0750
- name: Generate ssh key.
shell: cat /dev/zero | ssh-keygen -q -N ""
args:
creates: /root/.ssh/id_rsa.pub
# - name: Generate ssh key.
# shell: cat /dev/zero | ssh-keygen -q -N ""
# args:
# creates: /root/.ssh/id_rsa.pub
......@@ -2,12 +2,12 @@
- name: Include common tasks.
include: common-1.yml
- name: Fetch id_rsa.pub file from master.
fetch: src=/root/.ssh/id_rsa.pub dest=/tmp/fetched/ flat=yes
# - name: Fetch id_rsa.pub file from master.
# fetch: src=/root/.ssh/id_rsa.pub dest=/tmp/fetched/ flat=yes
- name: Set up ssh config.
template: src=ssh-config.j2 dest=/root/.ssh/config owner=root group=root mode=664
- name: Include more common tasks.
include: common-2.yml
# - name: Include more common tasks.
# include: common-2.yml
......@@ -8,4 +8,8 @@
lineinfile: destfile="/etc/squid3/squid.conf" regexp="^acl localnet" insertafter="^#acl localnet"
line="acl localnet src {{ hostvars[groups['all'][0]]['local_net'] }}"
state=present
lineinfile: destfile="/etc/squid3/squid.conf" regexp="^#http_access allow localnet"
line="http_access allow localnet"
state=present
tags: config
......@@ -38,39 +38,44 @@ class Manager:
:return:
"""
inventory_groups = []
all_hosts = []
all_group = ansible.inventory.group.Group(name="all")
host = self.inventory['master']
all_hosts.append(host['name'] + '.vm.okeanos.grnet.gr')
ansible_host = ansible.inventory.host.Host(name=all_hosts[-1])
for host in self.inventory['slaves']:
all_hosts.append(host['name'] + '.local')
ansible_host = ansible.inventory.host.Host(name=all_hosts[-1])
self.ansible_inventory = ansible.inventory.Inventory(host_list=all_hosts)
all_group = self.ansible_inventory.get_group('all')
all_group.set_variable('ansible_ssh_private_key_file', self.temp_file)
all_group.set_variable('local_net', self.cidr)
inventory_groups.append(all_group)
all_ansible_hosts = all_group.get_hosts()
master_group = ansible.inventory.group.Group(name='master')
all_group.add_child_group(master_group)
host = self.inventory['master']
ansible_host = ansible.inventory.host.Host(name=host['name'] + '.vm.okeanos.grnet.gr')
# master_group.set_variable('local_net', self.cidr)
ansible_host.set_variable('ansible_ssh_private_key_file', self.temp_file)
ansible_host = all_ansible_hosts[0]
ansible_host.set_variable('internal_ip', self.inventory['master']['ip'])
ansible_host.set_variable('id', 0)
master_group.add_host(ansible_host)
inventory_groups.append(master_group)
slave_group = ansible.inventory.group.Group(name='slaves')
all_group.add_child_group(slave_group)
slave_group.set_variable('proxy_env', {'http_proxy': 'http://' + self.inventory['master']['name'] + '.local:3128'})
for host_id, host in enumerate(self.inventory["slaves"], start=1):
ansible_host = ansible.inventory.host.Host(name=host['name'] + '.local')
# host_vars['internal_ip'] = host['ip']
# for var_key, var_value in host_vars.iteritems():
# ansible_host.set_variable(var_key, var_value)
self.ansible_inventory.add_group(master_group)
all_group.add_child_group(master_group)
slaves_group = ansible.inventory.group.Group(name='slaves')
slaves_group.set_variable('proxy_env', {'http_proxy': 'http://' + self.inventory['master']['name'] + '.local:3128'})
# slaves_group.set_variable('http_proxy', 'http://' + self.inventory['master']['name'] + '.local:3128')
for host_id, host in enumerate(self.inventory['slaves'], start=1):
ansible_host = all_ansible_hosts[host_id]
ansible_host.set_variable('internal_ip', host['ip'])
ansible_host.set_variable('id', host_id)
slave_group.add_host(ansible_host)
inventory_groups.append(slave_group)
# ansible_host.set_variable('http_proxy', 'http://' + self.inventory['master']['name'] + '.local:3128')
# print ansible_host.get_variables()
slaves_group.add_host(ansible_host)
self.ansible_inventory.add_group(slaves_group)
all_group.add_child_group(slaves_group)
self.ansible_inventory = ansible.inventory.Inventory(host_list=None)
for group in inventory_groups:
self.ansible_inventory.add_group(group)
print self.ansible_inventory.groups_list()
return self.ansible_inventory
......@@ -102,12 +107,17 @@ if __name__ == "__main__":
u'vpn': {u'type': u'MAC_FILTERED', u'id': u'143499'},
u'subnet': {u'cidr': u'192.168.0.0/24', u'gateway_ip': u'192.168.0.1', u'id': u'142564'}}
manager = Manager(response)
manager.create_inventory()
manager.run_playbook(playbook_file="../../ansible/playbooks/testinventory.yml", tags=['hosts'])
# manager.run_playbook(playbook_file="../../ansible/playbooks/testinventory.yml", tags=['hosts'])
manager.run_playbook(playbook_file="../../ansible/playbooks/testproxy.yml", tags=['install'])
# manager.run_playbook(playbook_file="../../ansible/playbooks/common/install.yml", tags=['master'])
# manager.run_playbook(playbook_file="../../ansible/playbooks/proxy/proxy.yml", tags=['config'])
# manager.run_playbook(playbook_file="../../ansible/playbooks/proxy/proxy.yml")
# manager.run_playbook(playbook_file="../../ansible/playbooks/common/install.yml", tags=['slaves'])
# manager.run_playbook(playbook_file="../../ansible/playbooks/apache-hadoop/hadoop-install.yml")
# manager.run_playbook(playbook_file="../../ansible/playbooks/apache-flink/flink-install.yml")
# manager.run_playbook(playbook_file="../../ansible/playbooks/apache-kafka/kafka-install.yml")
manager.cleanup()
\ No newline at end of file
......@@ -52,12 +52,15 @@ if __name__ == "__main__":
time.sleep(15)
manager = Manager(provisioner_response)
manager.create_inventory()
manager.run_playbook(playbook_file="../../ansible/playbooks/testinventory.yml", tags=['hosts'])
# manager.run_playbook(playbook_file="../../ansible/playbooks/testinventory.yml", tags=['hosts'])
# manager.run_playbook(playbook_file="../../ansible/playbooks/testproxy.yml", tags=['install'])
# manager.run_playbook(playbook_file="../../ansible/playbooks/common/install.yml", tags=['master'])
# manager.run_playbook(playbook_file="../../ansible/playbooks/proxy/proxy.yml")
# manager.run_playbook(playbook_file="../../ansible/playbooks/common/install.yml", tags=['slaves'])
manager.run_playbook(playbook_file="../../ansible/playbooks/common/install.yml", tags=['master'])
manager.run_playbook(playbook_file="../../ansible/playbooks/proxy/proxy.yml")
manager.run_playbook(playbook_file="../../ansible/playbooks/common/install.yml", tags=['slaves'])
manager.run_playbook(playbook_file="../../ansible/playbooks/apache-hadoop/hadoop-install.yml")
manager.run_playbook(playbook_file="../../ansible/playbooks/apache-flink/flink-install.yml")
manager.run_playbook(playbook_file="../../ansible/playbooks/apache-kafka/kafka-install.yml")
# INSERT PLAYBOOKS HERE
......
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