From 835e04bcb415408dddfb0c7b0ec4b616b38b6c75 Mon Sep 17 00:00:00 2001
From: matt01671 <matt01671@gmail.com>
Date: Thu, 7 May 2020 10:46:08 +1200
Subject: [PATCH] separated cluster and instance

---
 ansible/all-in-one.yaml                       | 43 -------------------
 ansible/create-cluster.sh                     |  3 ++
 ansible/create-cluster.yaml                   |  9 ++++
 ...{run-all-in-one.sh => create-instances.sh} |  0
 ansible/create-instances.yaml                 | 43 +++++++++++++++++++
 ansible/host_vars/docker.yaml                 |  6 +--
 ansible/host_vars/nectar.yaml                 |  6 +--
 ansible/hosts                                 |  6 +--
 .../slaves-cluster/templates/set-cluster-t.sh |  2 +-
 9 files changed, 65 insertions(+), 53 deletions(-)
 delete mode 100755 ansible/all-in-one.yaml
 create mode 100755 ansible/create-cluster.sh
 create mode 100644 ansible/create-cluster.yaml
 rename ansible/{run-all-in-one.sh => create-instances.sh} (100%)
 create mode 100755 ansible/create-instances.yaml

diff --git a/ansible/all-in-one.yaml b/ansible/all-in-one.yaml
deleted file mode 100755
index d113aa1..0000000
--- a/ansible/all-in-one.yaml
+++ /dev/null
@@ -1,43 +0,0 @@
-# - hosts: localhost
-#   vars_files:
-#     - host_vars/nectar.yaml
-#   gather_facts: true
-
-#   roles:
-#     - role: openstack-common
-#     - role: openstack-volume
-#     - role: openstack-security-group
-#     - role: cluster-security-group
-#     - role: openstack-instance
-
-# - hosts: instances
-#   vars_files:
-#     - host_vars/docker.yaml
-#   gather_facts: true
-
-#   roles:
-#     - role: openstack-proxy
-#     - role: all-dependencies
-#     - role: all-mount
-#     - role: all-docker
-
-# - hosts: web
-#   vars_files:
-#     - host_vars/react.yaml
-#   gather_facts: true
-
-#   roles:
-#     - role: react-build
-
-- hosts: dbs
-  
-  roles:
-    - role: cluster-build
-
-- hosts: master
-
-  roles:
-    - role: slaves-cluster
-
-
-  
\ No newline at end of file
diff --git a/ansible/create-cluster.sh b/ansible/create-cluster.sh
new file mode 100755
index 0000000..2a47823
--- /dev/null
+++ b/ansible/create-cluster.sh
@@ -0,0 +1,3 @@
+#!/usr/bin/env bash
+
+. ./unimelb-comp90024-2020-grp-62-openrc.sh; ansible-playbook -i hosts --ask-become-pass create-cluster.yaml
\ No newline at end of file
diff --git a/ansible/create-cluster.yaml b/ansible/create-cluster.yaml
new file mode 100644
index 0000000..6931039
--- /dev/null
+++ b/ansible/create-cluster.yaml
@@ -0,0 +1,9 @@
+- hosts: dbs
+  
+  roles:
+    - role: cluster-build
+
+- hosts: master
+
+  roles:
+    - role: slaves-cluster
\ No newline at end of file
diff --git a/ansible/run-all-in-one.sh b/ansible/create-instances.sh
similarity index 100%
rename from ansible/run-all-in-one.sh
rename to ansible/create-instances.sh
diff --git a/ansible/create-instances.yaml b/ansible/create-instances.yaml
new file mode 100755
index 0000000..8546ff2
--- /dev/null
+++ b/ansible/create-instances.yaml
@@ -0,0 +1,43 @@
+- hosts: localhost
+  vars_files:
+    - host_vars/nectar.yaml
+  gather_facts: true
+
+  roles:
+    - role: openstack-common
+    - role: openstack-volume
+    - role: openstack-security-group
+    - role: cluster-security-group
+    - role: openstack-instance
+
+- hosts: instances
+  vars_files:
+    - host_vars/docker.yaml
+  gather_facts: true
+
+  roles:
+    - role: openstack-proxy
+    - role: all-dependencies
+    - role: all-mount
+    - role: all-docker
+
+- hosts: web
+  vars_files:
+    - host_vars/react.yaml
+  gather_facts: true
+
+  roles:
+    - role: react-build
+
+# - hosts: dbs
+  
+#   roles:
+#     - role: cluster-build
+
+# - hosts: master
+
+#   roles:
+#     - role: slaves-cluster
+
+
+  
\ No newline at end of file
diff --git a/ansible/host_vars/docker.yaml b/ansible/host_vars/docker.yaml
index bc49a97..2ec8ebd 100644
--- a/ansible/host_vars/docker.yaml
+++ b/ansible/host_vars/docker.yaml
@@ -1,4 +1,4 @@
 ---
-    volumes:
-      - device: /dev/vdb
-        mountpoint: /var/lib/docker
\ No newline at end of file
+volumes:
+  - device: /dev/vdb
+    mountpoint: /var/lib/docker
\ No newline at end of file
diff --git a/ansible/host_vars/nectar.yaml b/ansible/host_vars/nectar.yaml
index 862de34..5f1114c 100755
--- a/ansible/host_vars/nectar.yaml
+++ b/ansible/host_vars/nectar.yaml
@@ -55,15 +55,15 @@ cluster_security_group:
 
 # Instance
 instances:
-  - name: db1
+  - name: db-master-1
     volumes: ['dbvolume1']
     meta:
       group: master
-  - name: db2
+  - name: db-slave-1
     volumes: ['dbvolume2']
     meta:
         group: slaves
-  - name: db3
+  - name: db-slave-2
     volumes: ['dbvolume3']
     meta:
       group: slaves
diff --git a/ansible/hosts b/ansible/hosts
index 2b21702..3ea6080 100644
--- a/ansible/hosts
+++ b/ansible/hosts
@@ -1,11 +1,11 @@
 [web]
 
 [master]
-172.26.133.128 ansible_host=172.26.133.128
+172.26.133.58 ansible_host=172.26.133.58
 
 [slaves]
-172.26.134.57 ansible_host=172.26.134.57
-172.26.133.52 ansible_host=172.26.133.52
+172.26.132.78 ansible_host=172.26.132.78
+172.26.133.15 ansible_host=172.26.133.15
 
 [dbs:children]
 master
diff --git a/ansible/roles/slaves-cluster/templates/set-cluster-t.sh b/ansible/roles/slaves-cluster/templates/set-cluster-t.sh
index 1db0382..624fc50 100644
--- a/ansible/roles/slaves-cluster/templates/set-cluster-t.sh
+++ b/ansible/roles/slaves-cluster/templates/set-cluster-t.sh
@@ -1,7 +1,7 @@
 #!/usr/bin/env bash
 
 echo "== Set variables =="
-export declare -a nodes=(172.26.133.128 172.26.133.52 172.26.134.57) #NEED TO AUTOMATE
+export declare -a nodes=(172.26.133.58 172.26.132.78 172.26.133.15) #NEED TO AUTOMATE
 # export declare -a nodes=($1)
 export user=admin
 export pass=admin
-- 
GitLab