summaryrefslogtreecommitdiffstats
path: root/deploy/adapters/ansible/roles/database/tasks
diff options
context:
space:
mode:
authorcarey.xu <carey.xuhan@huawei.com>2015-12-17 18:16:12 +0800
committercarey.xu <carey.xuhan@huawei.com>2015-12-25 13:18:21 +0800
commitbb31ed2d10f1876a50353abb258c2a5be13e2da2 (patch)
tree7e716df5ccc99bb19b624ff41ffd77cc0e60fb10 /deploy/adapters/ansible/roles/database/tasks
parent21e1b393c0fc7f52c831882b53454877f6942495 (diff)
deploy mongodb as cluster for HA
JIRA: COMPASS-207 Change-Id: I1069bcc2d0dd97dd6a4c7bb61351be993d86b33a Signed-off-by: carey.xu <carey.xuhan@huawei.com>
Diffstat (limited to 'deploy/adapters/ansible/roles/database/tasks')
-rw-r--r--deploy/adapters/ansible/roles/database/tasks/main.yml5
-rwxr-xr-xdeploy/adapters/ansible/roles/database/tasks/mongodb_config.yml35
-rwxr-xr-x[-rw-r--r--]deploy/adapters/ansible/roles/database/tasks/mongodb_install.yml (renamed from deploy/adapters/ansible/roles/database/tasks/mongodb.yml)13
3 files changed, 41 insertions, 12 deletions
diff --git a/deploy/adapters/ansible/roles/database/tasks/main.yml b/deploy/adapters/ansible/roles/database/tasks/main.yml
index 20b6fe4b..bfdcb75b 100644
--- a/deploy/adapters/ansible/roles/database/tasks/main.yml
+++ b/deploy/adapters/ansible/roles/database/tasks/main.yml
@@ -9,4 +9,7 @@
when:
- inventory_hostname == haproxy_hosts.keys()[0]
-- include: mongodb.yml
+- include: mongodb_install.yml
+- include: mongodb_config.yml
+ when:
+ - inventory_hostname == haproxy_hosts.keys()[0]
diff --git a/deploy/adapters/ansible/roles/database/tasks/mongodb_config.yml b/deploy/adapters/ansible/roles/database/tasks/mongodb_config.yml
new file mode 100755
index 00000000..573b30a9
--- /dev/null
+++ b/deploy/adapters/ansible/roles/database/tasks/mongodb_config.yml
@@ -0,0 +1,35 @@
+---
+- name: copy replica js
+ template:
+ src: replica.js
+ dest: /opt/replica.js
+
+- name: init replica servers
+ shell: mongo compass /opt/replica.js
+
+- name: wait replica servers are ready
+ shell: mongo compass --eval 'printjson(rs.status())'|grep -E 'PRIMARY|SECONDARY'|wc -l
+ register: servers
+ until: servers.stdout|int == 3
+ retries: 20
+ delay: 3
+
+- debug: msg='{{ servers.stdout |int }}'
+
+- name: create mongodb user and db
+ mongodb_user:
+ login_host: "{{ internal_vip.ip }}"
+ database: ceilometer
+ name: ceilometer
+ password: "{{ CEILOMETER_DBPASS }}"
+ roles: 'readWrite,dbAdmin'
+ state: present
+
+- name: grant user privilege
+ mongodb_user:
+ login_host: "{{ internal_vip.ip }}"
+ database: ceilometer
+ name: ceilometer
+ password: "{{ CEILOMETER_DBPASS }}"
+ roles: 'readWrite,dbAdmin'
+ state: present
diff --git a/deploy/adapters/ansible/roles/database/tasks/mongodb.yml b/deploy/adapters/ansible/roles/database/tasks/mongodb_install.yml
index ada7f7ef..1e7988d2 100644..100755
--- a/deploy/adapters/ansible/roles/database/tasks/mongodb.yml
+++ b/deploy/adapters/ansible/roles/database/tasks/mongodb_install.yml
@@ -26,14 +26,5 @@
- name: write mongodb to monitor list
lineinfile: dest=/opt/service create=yes line={{ mongodb_service}}
-- wait_for: port=27017 delay=3 timeout=60 host={{ internal_vip.ip }}
-
-- name: create mongodb user
- run_once: True
- mongodb_user:
- login_host: "{{ internal_vip.ip }}"
- database: ceilometer
- name: ceilometer
- password: "{{ CEILOMETER_DBPASS }}"
- roles: 'readWrite,dbAdmin'
- state: present
+- name: wait for mongod ready
+ wait_for: host=0.0.0.0 port=27017 delay=10