diff --git a/Ansible/.DS_Store b/Ansible/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..303519d62799ae1fb120892d70f23ee65dacfea9 Binary files /dev/null and b/Ansible/.DS_Store differ diff --git a/Ansible/host_vars/couchdb.yaml b/Ansible/host_vars/couchdb.yaml new file mode 100644 index 0000000000000000000000000000000000000000..b2869192bc18e2a801699817f4c05e7675f23526 --- /dev/null +++ b/Ansible/host_vars/couchdb.yaml @@ -0,0 +1,9 @@ +- hosts: mrc.db + vars: + database_user: 'admin' + database_password: 'admin' + cookie: 'alexis' + ansible_python_interpreter: /usr/bin/python3.8 + + roles: + - role: \ No newline at end of file diff --git a/Ansible/host_vars/mrc.yaml b/Ansible/host_vars/mrc.yaml new file mode 100644 index 0000000000000000000000000000000000000000..6be6d0899bc6aa7cd34b26f6a87cd4d19864d827 --- /dev/null +++ b/Ansible/host_vars/mrc.yaml @@ -0,0 +1,35 @@ +# Common vars +availability_zone: melbourne-qh2-uom + +# Volume +volumes: + - vol_name: volPrueba1 + vol_size: 10 + - vol_name: volPrueba2 + vol_size: 10 + +#Security group +security_groups: + - name: demo_ssh + description: "Demo security group for SSH access" + protocol: tcp + port_range_min: 22 + port_range_max: 22 + remote_ip_prefix: 0.0.0.0/0 + - name: demo_http + description: "Demo security group for HTTP" + protocol: tcp + port_range_min: 80 + port_range_max: 80 + remote_ip_prefix: 0.0.0.0/0 + +#Instance +instances: + - name: prueba1 + volumes: 'volPrueba1' + - name: prueba2 + volumes: 'volPrueba2' + +instance_image: 34ce7ec8-50f2-4604-a38f-7d81d1c2041d #f8b79936-6616-4a22-b55d-0d0a1d27bceb +instance_key_name: couchTestKey +instance_flavor: uom.mse.1c4g \ No newline at end of file diff --git a/Ansible/inventory.ini b/Ansible/inventory.ini new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/Ansible/mrc.yaml b/Ansible/mrc.yaml new file mode 100644 index 0000000000000000000000000000000000000000..c3616984b4a6c4c975440b018b9c9c1b93b81310 --- /dev/null +++ b/Ansible/mrc.yaml @@ -0,0 +1,15 @@ +- hosts: localhost + vars: + ansible_python_interpreter: /usr/bin/python3.8 + vars_files: + - host_vars/mrc.yaml + gather_facts: true + + roles: + - role: openstack-common + - role: openstack-images + - role: openstack-volume + - role: openstack-security-group + - role: openstack-instance + - role: openstack-IP +# - role: openstack-volume-snapshot \ No newline at end of file diff --git a/Ansible/roles/.DS_Store b/Ansible/roles/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..a678e9ccbf602db43c82f66b7eb3fe52b6f7be06 Binary files /dev/null and b/Ansible/roles/.DS_Store differ diff --git a/Ansible/roles/openstack-IP/main.yaml b/Ansible/roles/openstack-IP/main.yaml new file mode 100644 index 0000000000000000000000000000000000000000..274029c38d4972e09b59e121f0c99fe8a25ed124 --- /dev/null +++ b/Ansible/roles/openstack-IP/main.yaml @@ -0,0 +1,5 @@ +- hosts: host1 + tasks: + - name: Show host's ip + debug: + msg: "{{ ansible_ssh_host }}" \ No newline at end of file diff --git a/Ansible/roles/openstack-common/.DS_Store b/Ansible/roles/openstack-common/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..be96e3e647ce5519c2c4cfefb36bf36645fb9fcf Binary files /dev/null and b/Ansible/roles/openstack-common/.DS_Store differ diff --git a/Ansible/roles/openstack-common/tasks/main.yaml b/Ansible/roles/openstack-common/tasks/main.yaml new file mode 100644 index 0000000000000000000000000000000000000000..efa78107786e5e68b63b8ed472754f03de773f8e --- /dev/null +++ b/Ansible/roles/openstack-common/tasks/main.yaml @@ -0,0 +1,22 @@ +- name: Install pip + become: yes + apt: + name: ['python3-pip'] + state: latest + update_cache: yes + when: ansible_distribution == "Ubuntu" +# sudo apt-get update; sudo apt-get install python-pip + +- name: Update pip + become: yes + pip: + name: ['pip'] + state: latest +# pip install --upgrade pip + +- name: Install openstacksdk + become: yes + pip: + name: ['openstacksdk'] + state: latest +# pip install openstacksdk \ No newline at end of file diff --git a/Ansible/roles/openstack-couchdb/tasks/main.yml b/Ansible/roles/openstack-couchdb/tasks/main.yml new file mode 100644 index 0000000000000000000000000000000000000000..78bafceb972d0973c176b82af12b25231a349278 --- /dev/null +++ b/Ansible/roles/openstack-couchdb/tasks/main.yml @@ -0,0 +1,13 @@ +- name: Bind the clustered interface to all IP addresses availble on this machine + + command: curl -X PUT http://{{ database_user }}:{{ database_password }}@127.0.0.1:5984/_node/_local/_config/httpd/bind_address -d '"0.0.0.0"' + +- name: Set the UUID of the node to + + command: curl -X PUT http://{{ database_user }}:{{ database_password }}@127.0.0.1:5984/_node/_local/_config/couchdb/uuid -d '"{{ database_uuid }}"' + +- name: Set the shared http secret for cookie creation + + command: curl -X PUT http://{{ database_user }}:{{ database_password }}@127.0.0.1:5984/_node/_local/_config/couch_httpd_auth/secret -d '"{{ database_secret }}" + + - name: Setup cluster diff --git a/Ansible/roles/openstack-images/.DS_Store b/Ansible/roles/openstack-images/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..fb81acb434381dab2a77292b929357eaf44dd81c Binary files /dev/null and b/Ansible/roles/openstack-images/.DS_Store differ diff --git a/Ansible/roles/openstack-images/tasks/main.yaml b/Ansible/roles/openstack-images/tasks/main.yaml new file mode 100644 index 0000000000000000000000000000000000000000..79fbfbf139092edce88bf192b79679cd98c51e8f --- /dev/null +++ b/Ansible/roles/openstack-images/tasks/main.yaml @@ -0,0 +1,15 @@ +# Show all available Openstack images +- name: Retrieve all available Openstack images + os_image_info: + register: image_result + +- name: Get image names and Ids + set_fact: + image_facts: "{{ image_facts|default([]) + [ {'name': item.name, 'id': item.id} ] }}" + loop: '{{ image_result.openstack_image }}' + when: item.name is defined + +- name: Show images + debug: + msg: "Image name: {{ item.name }}; Image id: {{ item.id }}" + loop: '{{ image_facts }}' diff --git a/Ansible/roles/openstack-instance/.DS_Store b/Ansible/roles/openstack-instance/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..dab08dd871431ca9132d86d21e0aad1abbe1b54e Binary files /dev/null and b/Ansible/roles/openstack-instance/.DS_Store differ diff --git a/Ansible/roles/openstack-instance/tasks/main.yaml b/Ansible/roles/openstack-instance/tasks/main.yaml new file mode 100644 index 0000000000000000000000000000000000000000..57bade5365a6f3b58da990c467e1ace4e3ba6074 --- /dev/null +++ b/Ansible/roles/openstack-instance/tasks/main.yaml @@ -0,0 +1,38 @@ +--- +# Create an instance on MRC +- name: Create an instance + os_server: + name: '{{ item.name }}' + image: '{{ instance_image }}' + key_name: '{{ instance_key_name }}' + flavor: '{{ instance_flavor }}' + availability_zone: '{{ availability_zone }}' + security_groups: '{{ sg_names }}' + volumes: '{{ item.volumes }}' + auto_floating_ip: yes + wait: yes + timeout: 600 + state: present + loop: '{{ instances }}' + register: os_instance + +- debug: + msg: "Instance {{ item.openstack.name }} has been created. IP address is {{ item.openstack.public_v4 }}" + loop: '{{ os_instance.results }}' + when: item.openstack is defined + +- name: Wait for connection + wait_for: + host: "{{ item.openstack.public_v4 }}" + port: 22 + timeout: 240 + search_regex: OpenSSH + loop: '{{ os_instance.results }}' + when: item.openstack is defined + +- name: Add host + add_host: + name: '{{ item.openstack.public_v4 }}' + groups: COUCHGROUP + loop: '{{ os_instance.results }}' + when: item.openstack is defined \ No newline at end of file diff --git a/Ansible/roles/openstack-security-group/.DS_Store b/Ansible/roles/openstack-security-group/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..98d5e0394ffe78a5d2ed6c0e1232f86632b3c93f Binary files /dev/null and b/Ansible/roles/openstack-security-group/.DS_Store differ diff --git a/Ansible/roles/openstack-security-group/tasks/main.yaml b/Ansible/roles/openstack-security-group/tasks/main.yaml new file mode 100644 index 0000000000000000000000000000000000000000..3ee4b190b4a909be9dc7fb2e23b84bc19c87e26e --- /dev/null +++ b/Ansible/roles/openstack-security-group/tasks/main.yaml @@ -0,0 +1,27 @@ +--- +# Create a security group +- name: Create a security group + os_security_group: + name: '{{ item.name }}' + description: '{{ item.description }}' + state: present + loop: '{{ security_groups }}' + +- name: Create a list of security group names + set_fact: + sg_names: '{{ sg_names|default([]) + [ item.name ] }}' + loop: '{{ security_groups }}' + +- debug: + msg: "Security group(s) {{ sg_names }} have been created." + +# Create security group rules +- name: Create security group rules + os_security_group_rule: + security_group: '{{ item.name }}' + protocol: '{{ item.protocol }}' + port_range_min: '{{ item.port_range_min }}' + port_range_max: '{{ item.port_range_max }}' + remote_ip_prefix: '{{ item.remote_ip_prefix }}' + state: present + loop: '{{ security_groups }}' \ No newline at end of file diff --git a/Ansible/roles/openstack-volume-snapshot/.DS_Store b/Ansible/roles/openstack-volume-snapshot/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..03c72bd1edce31e5bf5890819cd238efb6ac6980 Binary files /dev/null and b/Ansible/roles/openstack-volume-snapshot/.DS_Store differ diff --git a/Ansible/roles/openstack-volume-snapshot/tasks/main.yaml b/Ansible/roles/openstack-volume-snapshot/tasks/main.yaml new file mode 100644 index 0000000000000000000000000000000000000000..be7c6b137500549ec580dc48e689397a73e46298 --- /dev/null +++ b/Ansible/roles/openstack-volume-snapshot/tasks/main.yaml @@ -0,0 +1,12 @@ +--- +# create volume snapshot +- name: Create volume snapshot + os_volume_snapshot: + state: present + volume: '{{ item.vol_name }}' + display_name: "{{ item.vol_name }}-{{ lookup('pipe', 'date +%Y-%m-%d-%H-%M-%S') }}" + wait: yes # wait until the snapshot is created + timeout: 600 + force: yes + availability_zone: '{{ availability_zone }}' + loop: '{{ volumes }}' \ No newline at end of file diff --git a/Ansible/roles/openstack-volume/tasks/main.yaml b/Ansible/roles/openstack-volume/tasks/main.yaml new file mode 100644 index 0000000000000000000000000000000000000000..e85e7fe5dc6f8573e7535e51fd8b5495e98155e2 --- /dev/null +++ b/Ansible/roles/openstack-volume/tasks/main.yaml @@ -0,0 +1,21 @@ +--- +# Create volumes from vars +- name: Create volume(s) on NeCTAR + os_volume: + display_name: '{{ item.vol_name }}' + size: '{{ item.vol_size }}' + availability_zone: '{{ availability_zone }}' + wait: yes + timeout: 600 + state: present + loop: '{{ volumes }}' + register: os_vol + +# Get a list of volume Ids from the reutrn value of os_volume +- name: Create a list of volume Ids + set_fact: + os_vol_ids: '{{ os_vol_ids|default([]) + [ item.id ] }}' + loop: '{{ os_vol.results }}' + +- debug: + msg: "Volume {{ os_vol_ids }} has been created" \ No newline at end of file diff --git a/Ansible/run-mrc.sh b/Ansible/run-mrc.sh new file mode 100644 index 0000000000000000000000000000000000000000..17c9fc8b032f7321896b30ce8f9f4a212301d980 --- /dev/null +++ b/Ansible/run-mrc.sh @@ -0,0 +1,3 @@ +. ./unimelb-comp90024-2021-grp-62-openrc.sh; ansible-playbook mrc.yaml + +#. ./unimelb-comp90024-2021-grp-62-openrc.sh; ansible-playbook couchdb.yaml \ No newline at end of file diff --git a/Ansible/unimelb-comp90024-2021-grp-62-openrc.sh b/Ansible/unimelb-comp90024-2021-grp-62-openrc.sh new file mode 100644 index 0000000000000000000000000000000000000000..3383b973793d27219e8c12b75e80bfa362ede95c --- /dev/null +++ b/Ansible/unimelb-comp90024-2021-grp-62-openrc.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash +# To use an OpenStack cloud you need to authenticate against the Identity +# service named keystone, which returns a **Token** and **Service Catalog**. +# The catalog contains the endpoints for all services the user/tenant has +# access to - such as Compute, Image Service, Identity, Object Storage, Block +# Storage, and Networking (code-named nova, glance, keystone, swift, +# cinder, and neutron). +# +# *NOTE*: Using the 3 *Identity API* does not necessarily mean any other +# OpenStack API is version 3. For example, your cloud provider may implement +# Image API v1.1, Block Storage API v2, and Compute API v2.0. OS_AUTH_URL is +# only for the Identity API served through keystone. +export OS_AUTH_URL=https://keystone.rc.nectar.org.au:5000/v3/ +# With the addition of Keystone we have standardized on the term **project** +# as the entity that owns the resources. +export OS_PROJECT_ID=c82f39882d974dbf8b5c925fb3eb4448 +export OS_PROJECT_NAME="unimelb-comp90024-2021-grp-62" +export OS_USER_DOMAIN_NAME="Default" +if [ -z "$OS_USER_DOMAIN_NAME" ]; then unset OS_USER_DOMAIN_NAME; fi +export OS_PROJECT_DOMAIN_ID="default" +if [ -z "$OS_PROJECT_DOMAIN_ID" ]; then unset OS_PROJECT_DOMAIN_ID; fi +# unset v2.0 items in case set +unset OS_TENANT_ID +unset OS_TENANT_NAME +# In addition to the owning entity (tenant), OpenStack stores the entity +# performing the action as the **user**. +export OS_USERNAME="alejandro.ariasrodriguez@student.unimelb.edu.au" +# With Keystone you pass the keystone password. +echo "Please enter your OpenStack Password for project $OS_PROJECT_NAME as user $OS_USERNAME: " +#read -sr OS_PASSWORD_INPUT +export OS_PASSWORD='NmQ0Y2IyOTkwOGIwZTQw' +# If your configuration has multiple regions, we set that information here. +# OS_REGION_NAME is optional and only valid in certain environments. +export OS_REGION_NAME="Melbourne" +# Don't leave a blank variable, unset it if it was empty +if [ -z "$OS_REGION_NAME" ]; then unset OS_REGION_NAME; fi +export OS_INTERFACE=public +export OS_IDENTITY_API_VERSION=3 \ No newline at end of file