Merge "Implement mongodb replication set cluster"

This commit is contained in:
Jenkins 2016-09-13 06:35:16 +00:00 committed by Gerrit Code Review
commit ea747d7ce2
7 changed files with 67 additions and 15 deletions

View File

@ -7,9 +7,7 @@ project_name: "ceilometer"
####################
ceilometer_database_name: "ceilometer"
ceilometer_database_user: "ceilometer"
# TODO(HuiKang): Update this so that connection to mongodb could be through
# haproxy; haproxy conf needs configurations for mongodb.
ceilometer_database_address: "{{ hostvars[groups['mongodb'][0]]['ansible_' + hostvars[groups['mongodb'][0]]['api_interface']]['ipv4']['address'] }}"
ceilometer_database_address: "{% for host in groups['mongodb'] %}{{ hostvars[host]['ansible_' + hostvars[host]['api_interface']]['ipv4']['address'] }}:{{ mongodb_port }}{% if not loop.last %},{% endif %}{% endfor %}"
####################

View File

@ -9,6 +9,9 @@ mongodb_image: "{{ docker_registry ~ '/' if docker_registry else '' }}{{ docker_
mongodb_tag: "{{ openstack_release }}"
mongodb_image_full: "{{ mongodb_image }}:{{ mongodb_tag }}"
####################
# Mongodb
####################
mongodb_replication_set_name: "rs0"

View File

@ -0,0 +1,19 @@
---
- name: Copying the mongodb replication set bootstrap script
template: src=bootstrap_cluster.js.j2 dest=/tmp/mongodb_bootstrap_replication_set.js
delegate_to: "{{ groups['mongodb'][0] }}"
run_once: True
- name: Bootstraping the mongodb replication set
command: "docker exec -t mongodb mongo {{ hostvars[inventory_hostname]['ansible_' + api_interface]['ipv4']['address'] }} --quiet --eval '{{ lookup('file','/tmp/mongodb_bootstrap_replication_set.js') }}'"
register: bootstrap_mongodb_cluster
failed_when: "{{ (bootstrap_mongodb_cluster.stdout|from_json).ok != 1 }}"
delegate_to: "{{ groups['mongodb'][0] }}"
run_once: True
- name: Deleting the mongodb replication set bootstrap script
file: path=/tmp/mongodb_bootstrap_replication_set.js state=absent
changed_when: false
failed_when: false
delegate_to: "{{ groups['mongodb'][0] }}"
run_once: True

View File

@ -11,3 +11,16 @@
- "/etc/localtime:/etc/localtime:ro"
- "kolla_logs:/var/log/kolla/"
- "mongodb:/var/lib/mongodb"
- name: Waiting for the mongodb startup
wait_for: host={{ hostvars[inventory_hostname]['ansible_' + api_interface]['ipv4']['address'] }} port={{ mongodb_port }}
- name: Checking current replication status
command: "docker exec -t mongodb mongo {{ hostvars[inventory_hostname]['ansible_' + api_interface]['ipv4']['address'] }} --quiet --eval rs.status().ok"
register: mongodb_replication_status
changed_when: false
delegate_to: "{{ groups['mongodb'][0] }}"
run_once: True
- include: "bootstrap_cluster.yml"
when: mongodb_replication_status.stdout != "1"

View File

@ -0,0 +1,14 @@
printjson(rs.initiate(
{
"_id" : "{{ mongodb_replication_set_name }}",
"version" : 1,
"members" : [
{% for host in groups["mongodb"] %}
{
"_id" : {{ loop.index }},
"host" : "{{ hostvars[host]['ansible_' + storage_interface]['ipv4']['address'] }}:{{ mongodb_port }}"
}{% if not loop.last %},{% endif %}
{% endfor %}
]
}
))

View File

@ -1,15 +1,17 @@
# mongodb.conf
systemLog:
destination: file
logAppend: true
path: /var/log/kolla/mongodb/mongodb.log
# Where to store the data.
dbpath = /var/lib/mongodb
storage:
dbPath: /var/lib/mongodb
# Enable journaling, http://www.mongodb.org/display/DOCS/Journaling
journal:
enabled: true
# where to log
logpath = /var/log/kolla/mongodb/mongodb.log
net:
bindIp: {{ hostvars[inventory_hostname]['ansible_' + api_interface]['ipv4']['address'] }}
port: {{ mongodb_port }}
logappend = true
bind_ip = {{ hostvars[inventory_hostname]['ansible_' + api_interface]['ipv4']['address'] }}
port = {{ mongodb_port }}
# Enable journaling, http://www.mongodb.org/display/DOCS/Journaling
journal = true
replication:
replSetName: {{ mongodb_replication_set_name }}

View File

@ -0,0 +1,3 @@
---
features:
- Implement MongoDB replicate set cluster