Merge "Implement mongodb replication set cluster"
This commit is contained in:
commit
ea747d7ce2
@ -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 %}"
|
||||
|
||||
|
||||
####################
|
||||
|
@ -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"
|
||||
|
19
ansible/roles/mongodb/tasks/bootstrap_cluster.yml
Normal file
19
ansible/roles/mongodb/tasks/bootstrap_cluster.yml
Normal 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
|
@ -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"
|
||||
|
14
ansible/roles/mongodb/templates/bootstrap_cluster.js.j2
Normal file
14
ansible/roles/mongodb/templates/bootstrap_cluster.js.j2
Normal 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 %}
|
||||
]
|
||||
}
|
||||
))
|
@ -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 }}
|
||||
|
@ -0,0 +1,3 @@
|
||||
---
|
||||
features:
|
||||
- Implement MongoDB replicate set cluster
|
Loading…
Reference in New Issue
Block a user