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

Added wait_for_ssh playbook, added proxy_env to some tasks, added handler to restart squid proxy

parent 26c8eed5
---
- name: Wait for port 22 to be ready
hosts: master
tasks:
- local_action: wait_for port=22 host="{{ inventory_hostname }}" search_regex=OpenSSH delay=5
tags: master
---
- name: Copy hosts file.
template: src=hosts.j2 dest=/etc/hosts backup=no owner=root group=root mode=0750
- name: Upgrade packages.
apt: upgrade=dist update_cache=yes
environment: proxy_env
- name: Install the latest Java 7.
apt: name=openjdk-7-jdk state=latest install_recommends=no update_cache=yes
- name: Copy hosts file.
template: src=hosts.j2 dest=/etc/hosts backup=no owner=root group=root mode=0750
environment: proxy_env
- name: Copy environment file.
copy: src=environment dest=/etc/environment backup=no owner=root group=root mode=0750
......
......@@ -2,6 +2,6 @@
- name: Include common tasks.
include: common-1.yml
- name: Include more common tasks.
include: common-2.yml
# - name: Include more common tasks.
# include: common-2.yml
{% for master in groups["master"] %}
Host {{ master }}
Host {{ master }}
StrictHostKeyChecking no
{% endfor %}
{% for slave in groups["slaves"] %}
Host {{ slave }}
Host {{ slave }}
StrictHostKeyChecking no
{% endfor %}
......
---
- name: restart squid3
action: service name=squid3 state=restarted
# enabled=yes
......@@ -8,11 +8,15 @@
lineinfile: destfile="/etc/squid3/squid.conf" regexp="^acl localnet" insertafter="^#acl localnet"
line="acl localnet src {{ hostvars[groups['all'][0]]['local_net'] }}"
state=present
notify:
- restart squid3
tags: config
- name: Configure squid http proxy 2
lineinfile: destfile="/etc/squid3/squid.conf" regexp="^#http_access allow localnet"
line="http_access allow localnet"
state=present
notify:
- restart squid3
tags: config
......@@ -23,11 +23,9 @@ class Manager:
with tempfile.NamedTemporaryFile(mode='w', delete=False) as kf:
kf.write(provisioner_response['pk'])
self.temp_file = kf.name
print self.temp_file
# print self.temp_file
ansible.constants.ANSIBLE_SSH_ARGS = '-o "ProxyCommand ssh -i %s -o StrictHostKeyChecking=no -W %%h:%%p root@%s.vm.okeanos.grnet.gr"' \
% (self.temp_file, self.inventory['master']['name'])
# ansible.constants.ANSIBLE_SSH_ARGS = '-o "ProxyCommand ssh root@%s.vm.okeanos.grnet.gr nc %%h %%p"' \
# % self.inventory['master']['name']
# ansible.constants.DEFAULT_PRIVATE_KEY_FILE = self.temp_file
ansible.constants.HOST_KEY_CHECKING = False
ansible.constants.DEFAULT_GATHERING = 'explicit'
......@@ -63,19 +61,18 @@ class Manager:
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('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)
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)
print self.ansible_inventory.groups_list()
# print self.ansible_inventory.groups_list()
return self.ansible_inventory
......@@ -87,7 +84,6 @@ class Manager:
stats = callbacks.AggregateStats()
playbook_cb = callbacks.PlaybookCallbacks(verbose=utils.VERBOSITY)
runner_cb = callbacks.PlaybookRunnerCallbacks(stats, verbose=utils.VERBOSITY)
# print self.ansible_inventory.get_group('all').get_hosts()
pb = PlayBook(playbook=playbook_file, inventory=self.ansible_inventory, stats=stats,
callbacks=playbook_cb,
runner_callbacks=runner_cb, only_tags=tags)
......@@ -96,6 +92,7 @@ class Manager:
def cleanup(self):
os.remove(self.temp_file)
if __name__ == "__main__":
response = {u'ips': [{u'floating_network_id': u'2216',
u'floating_ip_address': u'83.212.118.6',
......@@ -111,6 +108,7 @@ if __name__ == "__main__":
# 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/wait_for_ssh.yml")
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'])
......@@ -118,4 +116,4 @@ if __name__ == "__main__":
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
manager.cleanup()
......@@ -47,14 +47,14 @@ if __name__ == "__main__":
provisioner_response['nodes']['slaves'][i]['internal_ip'] = slave_ip
provisioner_response['pk'] = provisioner.get_private_key()
print provisioner_response
print 'response = ', provisioner_response
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/testproxy.yml", tags=['install'])
manager.run_playbook(playbook_file="../../ansible/playbooks/wait_for_ssh.yml")
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'])
......
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