From 0a605e6106ac149c6e5baebac97f99523b5347ee Mon Sep 17 00:00:00 2001
From: alex <dariasrodrig@student.unimelb.edu.au>
Date: Fri, 28 May 2021 00:23:22 +1000
Subject: [PATCH] install couchdb form scratch

---
 Ansible/all-in-one.yaml                       |  7 ++--
 Ansible/cluster_setup.sh                      | 11 ++++--
 Ansible/host_vars/mrc.yaml                    |  6 ++--
 Ansible/install_couchdb.sh                    | 34 +++++++++++++++++++
 Ansible/roles/openstack-proxy/tasks/main.yaml | 16 +++++++++
 .../openstack-run-script/tasks/main.yaml      | 18 +++++++++-
 6 files changed, 81 insertions(+), 11 deletions(-)
 create mode 100644 Ansible/install_couchdb.sh
 create mode 100644 Ansible/roles/openstack-proxy/tasks/main.yaml

diff --git a/Ansible/all-in-one.yaml b/Ansible/all-in-one.yaml
index f61918b..fb0e13c 100644
--- a/Ansible/all-in-one.yaml
+++ b/Ansible/all-in-one.yaml
@@ -16,11 +16,10 @@
 
 - hosts: COUCHGROUP
   gather_facts: true
-
-- hosts: COUCHGROUP
   roles:
-    - role: openstack-run-script
-  #roles:
+      - role: openstack-proxy
+      - role: openstack-run-script
+ 
 
     
 
diff --git a/Ansible/cluster_setup.sh b/Ansible/cluster_setup.sh
index 2852291..cc1867f 100644
--- a/Ansible/cluster_setup.sh
+++ b/Ansible/cluster_setup.sh
@@ -1,9 +1,14 @@
 #!/bin/bash
 
 echo "== Set variables =="
-export declare nodes=$1
-export declare -a nodes=($2)
-export VERSION='3.0.0'
+
+declare var1= echo $1
+
+"I was run:" > msg.txt
+echo $1 >>msg.txt 
+export declare nodes=($1 $2)
+#export declare -a nodes=($2)
+#export VERSION='3.0.0'
 export masternode=`echo ${nodes} | cut -f1 -d' '`
 export declare othernodes=`echo ${nodes[@]} | sed s/${masternode}//`
 export size=${#nodes[@]}
diff --git a/Ansible/host_vars/mrc.yaml b/Ansible/host_vars/mrc.yaml
index fa348d9..8ffa8d6 100644
--- a/Ansible/host_vars/mrc.yaml
+++ b/Ansible/host_vars/mrc.yaml
@@ -50,11 +50,11 @@ security_groups:
 
 #Instance
 instances:
-  - name: couchdb1
+  - name: prueba4
     volumes: 'volumedb1'
-  - name: couchdb2
+  - name: prueba5
     volumes: 'volumedb2'
 
-instance_image: 34ce7ec8-50f2-4604-a38f-7d81d1c2041d #f8b79936-6616-4a22-b55d-0d0a1d27bceb
+instance_image: 916cad7a-c545-48b2-b36c-d509ee63b3ce #f8b79936-6616-4a22-b55d-0d0a1d27bceb
 instance_key_name: testkey
 instance_flavor: uom.mse.1c4g
\ No newline at end of file
diff --git a/Ansible/install_couchdb.sh b/Ansible/install_couchdb.sh
new file mode 100644
index 0000000..807d759
--- /dev/null
+++ b/Ansible/install_couchdb.sh
@@ -0,0 +1,34 @@
+echo "====== getting ip ======"
+NODENAME=$(/sbin/ip -o -4 addr list eth0 | awk '{print $4}' | cut -d/ -f1)
+echo "nodename couchdb@{$NODENAME}"
+
+# Enabling Apache CouchDB repository.
+sudo apt update && sudo apt install -y curl apt-transport-https gnupg
+curl -L https://couchdb.apache.org/repo/bintray-pubkey.asc | sudo apt-key add -
+echo "deb https://apache.bintray.com/couchdb-deb bionic main" | sudo tee -a /etc/apt/sources.list
+
+# Set the password variable.
+echo "== setting password for couchdb ===="
+COUCHDB_PASSWORD=admin
+
+# Bindaddress: 0.0.0.0 (does not bind to anything).
+echo "== Setting up cluster variable for couch =="
+echo "couchdb couchdb/mode select clustered
+couchdb couchdb/mode seen true
+couchdb couchdb/nodename string couchdb@${NODENAME}
+couchdb couchdb/nodename seen true
+couchdb couchdb/cookie string elmo
+couchdb couchdb/cookie seen true
+couchdb couchdb/bindaddress string 0.0.0.0
+couchdb couchdb/bindaddress seen true
+couchdb couchdb/adminpass password ${COUCHDB_PASSWORD}
+couchdb couchdb/adminpass seen true
+couchdb couchdb/adminpass_again password ${COUCHDB_PASSWORD}
+couchdb couchdb/adminpass_again seen true" | sudo debconf-set-selections
+
+
+# update cache
+sudo apt update
+
+# Enter non-interactive mode instead of interactive mode here.
+sudo DEBIAN_FRONTEND=noninteractive apt-get install -y couchdb
diff --git a/Ansible/roles/openstack-proxy/tasks/main.yaml b/Ansible/roles/openstack-proxy/tasks/main.yaml
new file mode 100644
index 0000000..99c1c86
--- /dev/null
+++ b/Ansible/roles/openstack-proxy/tasks/main.yaml
@@ -0,0 +1,16 @@
+- name: Insert/Update "proxy setting" in /etc/environment
+  become: yes
+  become_user: root
+  blockinfile:
+    path: /etc/environment
+    block: |
+      HTTP_PROXY=http://wwwproxy.unimelb.edu.au:8000/
+      HTTPS_PROXY=http://wwwproxy.unimelb.edu.au:8000/
+      http_proxy=http://wwwproxy.unimelb.edu.au:8000/
+      https_proxy=http://wwwproxy.unimelb.edu.au:8000/
+      no_proxy=localhost,127.0.0.1,localaddress,172.16.0.0/12,.melbourne.rc.nectar.org.au,.storage.unimelb.edu.au,.cloud.unimelb.edu.au
+
+- name: Reboot VM that might have lots of updates to apply
+  become: yes
+  reboot:
+    reboot_timeout: 3600
diff --git a/Ansible/roles/openstack-run-script/tasks/main.yaml b/Ansible/roles/openstack-run-script/tasks/main.yaml
index 67cad0a..dcea678 100644
--- a/Ansible/roles/openstack-run-script/tasks/main.yaml
+++ b/Ansible/roles/openstack-run-script/tasks/main.yaml
@@ -1,2 +1,18 @@
+- name: example copying file with owner and permissions
+  copy:
+    src: /home/alex/CCC/project/comp90024/Ansible/install_couchdb.sh
+    dest: /home/ubuntu/install_couchdb.sh
+    owner: ubuntu
+    group: ubuntu
+    mode: 0644
+
+- name: change script permissions
+  become: yes
+  shell: |
+    sudo chmod 777 /home/ubuntu/install_couchdb.sh
+- name: install couchdb
+  become: yes
+  command: sh /home/ubuntu/install_couchdb.sh
+
 - name: Run script cluster
-  script: /home/alex/CCC/project/comp90024/Ansible/cluster_setup.sh COUCHGROUP[0] COUCHGROUP[1]
\ No newline at end of file
+  script: sh /home/alex/CCC/project/comp90024/Ansible/cluster_setup.sh COUCHGROUP[0] COUCHGROUP[1]
\ No newline at end of file
-- 
GitLab