diff options
Diffstat (limited to 'deploy/adapters/ansible/roles/database')
-rw-r--r-- | deploy/adapters/ansible/roles/database/tasks/main.yml | 5 | ||||
-rwxr-xr-x | deploy/adapters/ansible/roles/database/tasks/mongodb_config.yml | 35 | ||||
-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 | ||||
-rw-r--r-- | deploy/adapters/ansible/roles/database/templates/mongodb.conf | 3 | ||||
-rw-r--r-- | deploy/adapters/ansible/roles/database/templates/replica.js | 8 |
5 files changed, 51 insertions, 13 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 diff --git a/deploy/adapters/ansible/roles/database/templates/mongodb.conf b/deploy/adapters/ansible/roles/database/templates/mongodb.conf index 68b84d7a..18306154 100644 --- a/deploy/adapters/ansible/roles/database/templates/mongodb.conf +++ b/deploy/adapters/ansible/roles/database/templates/mongodb.conf @@ -1,4 +1,5 @@ # mongodb.conf -bind_ip = {{ internal_vip.ip }} +bind_ip = 0.0.0.0 +replSet = compass port = 27017 smallfiles = true diff --git a/deploy/adapters/ansible/roles/database/templates/replica.js b/deploy/adapters/ansible/roles/database/templates/replica.js new file mode 100644 index 00000000..3282cd6a --- /dev/null +++ b/deploy/adapters/ansible/roles/database/templates/replica.js @@ -0,0 +1,8 @@ +config = { _id:"compass", members:[ +{% for host in haproxy_hosts.values() %} +{% set pair = '%s:27017' % host %} + {_id:{{ loop.index0 }},host:"{{ pair }}"}, +{% endfor %} +] +}; +rs.initiate(config); |