diff --git a/ansible/group_vars/all.yml b/ansible/group_vars/all.yml index 121d988473..55aa9fd23f 100644 --- a/ansible/group_vars/all.yml +++ b/ansible/group_vars/all.yml @@ -84,6 +84,9 @@ rabbitmq_management_port: "15672" rabbitmq_cluster_port: "25672" rabbitmq_epmd_port: "4369" +mongodb_port: "27017" +mongodb_web_port: "28017" + haproxy_stats_port: "1984" keystone_public_port: "5000" @@ -178,6 +181,8 @@ enable_ironic: "no" enable_magnum: "no" enable_mistral: "no" enable_elk: "no" +enable_mongodb: "no" + ironic_keystone_user: "ironic" # Nova fake driver and the number of fake driver per compute node diff --git a/ansible/inventory/all-in-one b/ansible/inventory/all-in-one index 344ff0f279..aed8a3faff 100644 --- a/ansible/inventory/all-in-one +++ b/ansible/inventory/all-in-one @@ -27,6 +27,9 @@ control [rabbitmq:children] control +[mongodb:children] +control + [keystone:children] control diff --git a/ansible/inventory/multinode b/ansible/inventory/multinode index 828b0447a2..f6069d53fd 100644 --- a/ansible/inventory/multinode +++ b/ansible/inventory/multinode @@ -39,6 +39,9 @@ control [rabbitmq:children] control +[mongodb:children] +control + [keystone:children] control diff --git a/ansible/roles/haproxy/templates/haproxy.cfg.j2 b/ansible/roles/haproxy/templates/haproxy.cfg.j2 index fd520d6edd..e8af22ea1e 100644 --- a/ansible/roles/haproxy/templates/haproxy.cfg.j2 +++ b/ansible/roles/haproxy/templates/haproxy.cfg.j2 @@ -42,6 +42,14 @@ listen rabbitmq_management {% endfor %} {% endif %} +{% if enable_mongodb | bool %} +listen mongodb + bind {{ kolla_internal_address }}:{{ mongodb_port }} +{% for host in groups['mongodb'] %} + server {{ hostvars[host]['ansible_hostname'] }} {{ hostvars[host]['ansible_' + hostvars[host]['api_interface']]['ipv4']['address'] }}:{{ mongodb_port }} check inter 2000 rise 2 fall 5 +{% endfor %} +{% endif %} + {% if enable_keystone | bool %} listen keystone_public bind {{ kolla_internal_address }}:{{ keystone_public_port }} diff --git a/ansible/roles/mongodb/defaults/main.yml b/ansible/roles/mongodb/defaults/main.yml new file mode 100644 index 0000000000..168ab153ca --- /dev/null +++ b/ansible/roles/mongodb/defaults/main.yml @@ -0,0 +1,15 @@ +--- +project_name: "mongodb" + + +#################### +# Docker +#################### +mongodb_image: "{{ docker_registry ~ '/' if docker_registry else '' }}{{ docker_namespace }}/{{ kolla_base_distro }}-{{ kolla_install_type }}-mongodb" +mongodb_tag: "{{ openstack_release }}" +mongodb_image_full: "{{ mongodb_image }}:{{ mongodb_tag }}" + +#################### +# Mongodb +#################### + diff --git a/ansible/roles/mongodb/meta/main.yml b/ansible/roles/mongodb/meta/main.yml new file mode 100644 index 0000000000..6b4fff8fef --- /dev/null +++ b/ansible/roles/mongodb/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - { role: common } diff --git a/ansible/roles/mongodb/tasks/bootstrap.yml b/ansible/roles/mongodb/tasks/bootstrap.yml new file mode 100644 index 0000000000..3c7de0f393 --- /dev/null +++ b/ansible/roles/mongodb/tasks/bootstrap.yml @@ -0,0 +1,15 @@ +--- +- name: Starting mongodb bootstrap container + kolla_docker: + action: "start_container" + common_options: "{{ docker_common_options }}" + detach: False + environment: + KOLLA_BOOTSTRAP: + KOLLA_CONFIG_STRATEGY: "{{ config_strategy }}" + image: "{{ mongodb_image_full }}" + name: "bootstrap_mongodb" + restart_policy: "never" + volumes: + - "{{ node_config_directory }}/mongodb/:{{ container_config_directory }}/:ro" + - "mongodb:/var/lib/mongodb/" diff --git a/ansible/roles/mongodb/tasks/config.yml b/ansible/roles/mongodb/tasks/config.yml new file mode 100644 index 0000000000..def44cefd4 --- /dev/null +++ b/ansible/roles/mongodb/tasks/config.yml @@ -0,0 +1,23 @@ +--- +- name: Ensuring config directories exist + file: + path: "{{ node_config_directory }}/{{ item }}" + state: "directory" + recurse: yes + with_items: + - "mongodb" + +- name: Copying over config.json files for services + template: + src: "{{ item }}.json.j2" + dest: "{{ node_config_directory }}/{{ item }}/config.json" + with_items: + - "mongodb" + +- name: Copying over mongodb.conf + template: + src: "{{ item }}.j2" + dest: "{{ node_config_directory }}/mongodb/{{ item }}" + with_items: + - "mongodb.conf" + diff --git a/ansible/roles/mongodb/tasks/deploy.yml b/ansible/roles/mongodb/tasks/deploy.yml new file mode 100644 index 0000000000..fd4ed25937 --- /dev/null +++ b/ansible/roles/mongodb/tasks/deploy.yml @@ -0,0 +1,9 @@ +--- +- include: config.yml + when: inventory_hostname in groups['mongodb'] + +- include: bootstrap.yml + when: inventory_hostname in groups['mongodb'] + +- include: start.yml + when: inventory_hostname in groups['mongodb'] diff --git a/ansible/roles/mongodb/tasks/main.yml b/ansible/roles/mongodb/tasks/main.yml new file mode 100644 index 0000000000..b017e8b4ad --- /dev/null +++ b/ansible/roles/mongodb/tasks/main.yml @@ -0,0 +1,2 @@ +--- +- include: "{{ action }}.yml" diff --git a/ansible/roles/mongodb/tasks/pull.yml b/ansible/roles/mongodb/tasks/pull.yml new file mode 100644 index 0000000000..642e132c03 --- /dev/null +++ b/ansible/roles/mongodb/tasks/pull.yml @@ -0,0 +1,7 @@ +--- +- name: Pulling mongodb image + kolla_docker: + action: "pull_image" + common_options: "{{ docker_common_options }}" + image: "{{ mongodb_image_full }}" + when: inventory_hostname in groups['mongodb'] diff --git a/ansible/roles/mongodb/tasks/start.yml b/ansible/roles/mongodb/tasks/start.yml new file mode 100644 index 0000000000..3c5fd3ff31 --- /dev/null +++ b/ansible/roles/mongodb/tasks/start.yml @@ -0,0 +1,11 @@ +--- +- name: Starting mongodb container + kolla_docker: + action: "start_container" + common_options: "{{ docker_common_options }}" + image: "{{ mongodb_image_full }}" + name: "mongodb" + privileged: True + volumes: + - "{{ node_config_directory }}/mongodb/:{{ container_config_directory }}/:ro" + - "mongodb:/var/lib/mongodb" diff --git a/ansible/roles/mongodb/templates/mongodb.conf.j2 b/ansible/roles/mongodb/templates/mongodb.conf.j2 new file mode 100644 index 0000000000..0fbc4f494c --- /dev/null +++ b/ansible/roles/mongodb/templates/mongodb.conf.j2 @@ -0,0 +1,15 @@ +# mongodb.conf + +# Where to store the data. +dbpath = /var/lib/mongodb + +# where to log +logpath = /var/log/mongodb/mongodb.log + +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 diff --git a/ansible/roles/mongodb/templates/mongodb.json.j2 b/ansible/roles/mongodb/templates/mongodb.json.j2 new file mode 100644 index 0000000000..12a25fc5c2 --- /dev/null +++ b/ansible/roles/mongodb/templates/mongodb.json.j2 @@ -0,0 +1,11 @@ +{ + "command": "/usr/bin/mongod --unixSocketPrefix=/var/run/mongodb --config /etc/mongodb.conf run", + "config_files": [ + { + "source": "{{ container_config_directory }}/mongodb.conf", + "dest": "/etc/mongodb.conf", + "owner": "mongodb", + "perm": "0644" + } + ] +} diff --git a/ansible/roles/prechecks/tasks/port_checks.yml b/ansible/roles/prechecks/tasks/port_checks.yml index d62ba6ed31..5771742e5c 100644 --- a/ansible/roles/prechecks/tasks/port_checks.yml +++ b/ansible/roles/prechecks/tasks/port_checks.yml @@ -359,6 +359,30 @@ state: stopped when: inventory_hostname in groups['rabbitmq'] +- name: Checking free port for Mongodb + wait_for: + host: "{{ hostvars[inventory_hostname]['ansible_' + api_interface]['ipv4']['address'] }}" + port: "{{ mongodb_port }}" + connect_timeout: 1 + state: stopped + when: inventory_hostname in groups['mongodb'] + +- name: Checking free port for Mongodb Web + wait_for: + host: "{{ hostvars[inventory_hostname]['ansible_' + api_interface]['ipv4']['address'] }}" + port: "{{ mongodb_web_port }}" + connect_timeout: 1 + state: stopped + when: inventory_hostname in groups['mongodb'] + +- name: Checking free port for Mongodb HAProxy + wait_for: + host: "{{ kolla_internal_address }}" + port: "{{ mongodb_port }}" + connect_timeout: 1 + state: stopped + when: inventory_hostname in groups['haproxy'] + - name: Checking free port for Rsync wait_for: host: "{{ hostvars[inventory_hostname]['ansible_' + storage_interface]['ipv4']['address'] }}" diff --git a/ansible/site.yml b/ansible/site.yml index e7f62740ac..d35c45f4bf 100644 --- a/ansible/site.yml +++ b/ansible/site.yml @@ -168,3 +168,10 @@ - { role: mistral, tags: mistral, when: enable_mistral | bool } + +- hosts: + - mongodb + roles: + - { role: mongodb, + tags: mongodb, + when: enable_mongodb | bool } diff --git a/docker/mongodb/Dockerfile.j2 b/docker/mongodb/Dockerfile.j2 index 03cbb2a7fb..78f8b32b5c 100644 --- a/docker/mongodb/Dockerfile.j2 +++ b/docker/mongodb/Dockerfile.j2 @@ -15,9 +15,17 @@ RUN apt-get install -y --no-install-recommends mongodb-server \ {% endif %} -RUN mkdir -p /data/db +RUN mkdir -p /var/lib/mongodb /home/mongodb \ + && chown -R mongodb: /var/lib/mongodb /home/mongodb -# TODO(SamYaple): updated mongodb to match the rest of Kolla -#ENTRYPOINT exec /bin/mongod --dbpath /data/db --logpath /var/log/mongodb/mongo.log --noprealloc --smallfiles +COPY mongodb_sudoers /etc/sudoers.d/mongodb_sudoers +COPY extend_start.sh /usr/local/bin/kolla_extend_start + +RUN usermod -a -G kolla mongodb \ + && chmod 755 /usr/local/bin/kolla_extend_start \ + && chmod 750 /etc/sudoers.d \ + && chmod 440 /etc/sudoers.d/mongodb_sudoers {{ include_footer }} + +USER mongodb diff --git a/docker/mongodb/extend_start.sh b/docker/mongodb/extend_start.sh new file mode 100644 index 0000000000..f00369ff00 --- /dev/null +++ b/docker/mongodb/extend_start.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +echo "run extended start" + +# Bootstrap and exit if KOLLA_BOOTSTRAP variable is set. This catches all cases +# of the KOLLA_BOOTSTRAP variable being set, including empty. +if [[ "${!KOLLA_BOOTSTRAP[@]}" ]]; then + sudo chown mongodb: /var/lib/mongodb/ + exit 0 +fi diff --git a/docker/mongodb/mongodb_sudoers b/docker/mongodb/mongodb_sudoers new file mode 100644 index 0000000000..8a8f4e3cc8 --- /dev/null +++ b/docker/mongodb/mongodb_sudoers @@ -0,0 +1 @@ +%kolla ALL=(root) NOPASSWD: /usr/bin/chown mongodb\: /var/lib/mongodb/, /bin/chown mongodb\: /var/lib/mongodb/