aboutsummaryrefslogtreecommitdiffstats
path: root/deploy/adapters/ansible/roles/database/tasks
diff options
context:
space:
mode:
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