diff --git a/Deployment/playbooks/hosts.ini b/Deployment/playbooks/hosts.ini new file mode 100644 index 0000000000000000000000000000000000000000..7b1704890d8a67c952449cd2e0485bd16f7b18a8 --- /dev/null +++ b/Deployment/playbooks/hosts.ini @@ -0,0 +1,20 @@ +[master-instance] + +[master-instance:vars] +ansible_ssh_common_args='-o StrictHostKeyChecking=no' +ansible_ssh_private_key_file=~/.ssh/intance_key +ansible_user=ubuntu + + +[slave-instances] + +[slave-instances:vars] +ansible_ssh_common_args='-o StrictHostKeyChecking=no' +ansible_ssh_private_key_file=~/.ssh/intance_key +ansible_user=ubuntu + +[frontend-instance] +[frontend-instance:vars] +ansible_ssh_common_args='-o StrictHostKeyChecking=no' +ansible_ssh_private_key_file=~/.ssh/intance_key +ansible_user=ubuntu \ No newline at end of file diff --git a/Deployment/playbooks/roles/Apache/tasks/main.yaml b/Deployment/playbooks/roles/Apache/tasks/main.yaml new file mode 100644 index 0000000000000000000000000000000000000000..34c42b971306ee8f29354a8a2a6257d35fce5348 --- /dev/null +++ b/Deployment/playbooks/roles/Apache/tasks/main.yaml @@ -0,0 +1,8 @@ +- name: Install Apache + hosts: all + become: true + tasks: + - name: Install Apache package + apt: + name: apache2 + state: present \ No newline at end of file diff --git a/Deployment/playbooks/roles/Couchdb_container/tasks/main.yaml b/Deployment/playbooks/roles/Couchdb_container/tasks/main.yaml new file mode 100644 index 0000000000000000000000000000000000000000..3503a2e9693a9aface5413bc6aa0c371c7de5ab3 --- /dev/null +++ b/Deployment/playbooks/roles/Couchdb_container/tasks/main.yaml @@ -0,0 +1,30 @@ +- name: Provision CouchDB containers + hosts: slave-instances + become: true + tasks: + - name: Install Docker + apt: + name: docker.io + state: present + + - name: Pull CouchDB Docker image + docker_image: + name: couchdb + source: pull + + - name: Run CouchDB container + docker_container: + name: couchdb + image: couchdb + ports: + - "5984:5984" + restart_policy: always + +- name: Set up frontend application + hosts: frontend-instance + become: true + tasks: + - name: Install Docker + apt: + name: docker.io + state: present \ No newline at end of file diff --git a/Deployment/playbooks/roles/Couchdb_container/templates/docker-compose.yaml.j2 b/Deployment/playbooks/roles/Couchdb_container/templates/docker-compose.yaml.j2 new file mode 100644 index 0000000000000000000000000000000000000000..1d6be7364a0ddc3f13c7ab0a1cbd488957f31430 --- /dev/null +++ b/Deployment/playbooks/roles/Couchdb_container/templates/docker-compose.yaml.j2 @@ -0,0 +1,11 @@ +"version: '3' + +services: + jupyter: + image: jupyter/scipy-notebook + volumes: + - ~/notebooks:/home/jovyan/work + ports: + - 8888:8888 + command: > + bash -c "pip install couchdb nltk emoji textblob fuzzywuzzy wordcloud geopandas folium geoplot && start-notebook.sh" diff --git a/Deployment/playbooks/roles/openstack-instance/tasks/main.yaml b/Deployment/playbooks/roles/openstack-instance/tasks/main.yaml index 0367c67bcc02887953c64abf6fbd0469558773fd..58c38e38191f2dbbfdbdce0270f3e30d6d530787 100644 --- a/Deployment/playbooks/roles/openstack-instance/tasks/main.yaml +++ b/Deployment/playbooks/roles/openstack-instance/tasks/main.yaml @@ -1,6 +1,6 @@ --- -# Create an instance on NeCTAR -- name: Create an instance +# Create instances on NeCTAR +- name: Create master instance openstack.cloud.server: name: "{{ item.name }}" auto_floating_ip: false @@ -14,27 +14,105 @@ volumes: "{{ item.volumes }}" state: present wait: true - loop: "{{ instances }}" - register: os_instance + loop: "{{ master-instance }}" + register: master-instance - ansible.builtin.debug: msg: "Instance {{ item.server.name }} has been created. IP address is {{ item.server.access_ipv4 }}" - loop: "{{ os_instance.results }}" + loop: "{{ master-instance.results }}" when: item.server is defined - name: Wait for connection ansible.builtin.wait_for: - host: "{{ item.server.access_ipv4 }}" + host: "{{ master-instance.server.access_ipv4 }}" port: 22 timeout: 120 search_regex: OpenSSH - loop: "{{ os_instance.results }}" + loop: "{{ master-instance.results }}" when: item.server is defined # Add hosts to Ansible in-memory inventory - name: Add host ansible.builtin.add_host: name: "{{ item.server.access_ipv4 }}" - groups: COMP90024 - loop: "{{ os_instance.results }}" + groups: master-instance + loop: "{{ master-instance.results }}" + when: item.server is defined + +- name: Create slave instances + openstack.cloud.server: + name: "{{ item.name }}" + auto_floating_ip: false + availability_zone: "{{ availability_zone }}" + flavor: "{{ instance_flavor }}" + image: "{{ instance_image }}" + key_name: "{{ instance_key_name }}" + # network: "{{ instance_network }}" + security_groups: "{{ sg_names }}" + timeout: 600 + volumes: "{{ item.volumes }}" + state: present + wait: true + loop: "{{ slave-instances }}" + register: slave-instances + +- ansible.builtin.debug: + msg: "Instance {{ item.server.name }} has been created. IP address is {{ item.server.access_ipv4 }}" + loop: "{{ slave-instances.results }}" + when: item.server is defined + +- name: Wait for connection + ansible.builtin.wait_for: + host: "{{ slave-instances.server.access_ipv4 }}" + port: 22 + timeout: 120 + search_regex: OpenSSH + loop: "{{ slave-instances.results }}" + when: item.server is defined + +# Add hosts to Ansible in-memory inventory +- name: Add host + ansible.builtin.add_host: + name: "{{ item.server.access_ipv4 }}" + groups: master-instance + loop: "{{ slave-instances.results }}" + when: item.server is defined + +- name: Create frontend instance + openstack.cloud.server: + name: "{{ item.name }}" + auto_floating_ip: false + availability_zone: "{{ availability_zone }}" + flavor: "{{ instance_flavor }}" + image: "{{ instance_image }}" + key_name: "{{ instance_key_name }}" + # network: "{{ instance_network }}" + security_groups: "{{ sg_names }}" + timeout: 600 + volumes: "{{ item.volumes }}" + state: present + wait: true + loop: "{{ frontend-instance }}" + register: frontend-instance + +- ansible.builtin.debug: + msg: "Instance {{ item.server.name }} has been created. IP address is {{ item.server.access_ipv4 }}" + loop: "{{ frontend-instance.results }}" + when: item.server is defined + +- name: Wait for connection + ansible.builtin.wait_for: + host: "{{ frontend-instance.server.access_ipv4 }}" + port: 22 + timeout: 120 + search_regex: OpenSSH + loop: "{{ frontend-instance.results }}" + when: item.server is defined + +# Add hosts to Ansible in-memory inventory +- name: Add host + ansible.builtin.add_host: + name: "{{ item.server.access_ipv4 }}" + groups: master-instance + loop: "{{ frontend-instance.results }}" when: item.server is defined diff --git a/Deployment/playbooks/setup.yaml b/Deployment/playbooks/setup.yaml new file mode 100644 index 0000000000000000000000000000000000000000..88d4c6894ded6a037fd18cf519f0921f03a74c28 --- /dev/null +++ b/Deployment/playbooks/setup.yaml @@ -0,0 +1,40 @@ +- hosts: localhost + vars_files: + - vars/comm.yaml + gather_facts: true + + roles: + - role: openstack-common + - role: openstack-volume + - role: openstack-security-group + - role: openstack-instance + +- hosts: master-instance + vars_files: + - variable/couchdb_var.yaml + gather_facts: true + + roles: + - role: common + - role: couch-volumes + - role: docker + - role: git-clone + - role: twiter-api-key + - role: docker-compose + +- hosts: slave-instances + vars_files: + - variable/couchdb_var.yaml + gather_facts: true + + roles: + - role: couch-cluster + +- hosts: frontend-instance + gather_facts: true + + roles: + - role: common + - role: docker + - role: git-clone + - role: web-app-docker-compose \ No newline at end of file diff --git a/Deployment/playbooks/vars/comm.yaml b/Deployment/playbooks/vars/comm.yaml index 515b32e0772f66d52a8519136ac432662e5de95a..2588ae592d22964e638d867c0840087df3c644d6 100644 --- a/Deployment/playbooks/vars/comm.yaml +++ b/Deployment/playbooks/vars/comm.yaml @@ -33,12 +33,14 @@ security_groups: remote_ip_prefix: 0.0.0.0/0 # Instance -instances: +master-instance: - name: instance_1 volumes: ["data@instance_1"] +slave-instances: - name: instance_2 volumes: ["data@instance_2"] - name: instance_3 volumes: ["data@instance_3"] +frontend-instance: - name: instance_4 volumes: ["data@instance_4"]