openstack-ansible-os_ceilom.../tests/test-install-mongodb.yml

89 lines
2.6 KiB
YAML

---
# Copyright 2015, Rackspace US, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
- name: Install MongoDB for ceilometer
hosts: mongo_all
user: root
tasks:
- name: Install mongo packages
apt:
state: present
name: "{{ item }}"
with_items: "{{ packages_mongodb }}"
- name: Configure the MongoDB bind address
lineinfile:
dest: /etc/mongodb.conf
regexp: "^(#)?bind_ip"
line: "bind_ip = {{ ansible_host }}"
register: mongodb_bind
- name: Enable the MongoDB smallfiles option
lineinfile:
dest: /etc/mongodb.conf
regexp: "^(#)?smallfiles"
line: "smallfiles = true"
register: mongodb_smallfiles
- name: Restart mongodb
service:
name: mongodb
state: restarted
when:
- mongodb_bind | changed or mongodb_smallfiles | changed
register: mongodb_restart
- name: Wait for mongodb to come back online after the restart
wait_for:
host: "{{ ansible_host }}"
port: 27017
delay: 5
timeout: 30
when:
- mongodb_restart is defined
- mongodb_restart | changed
- name: Test mongodb connectivity
command: "mongo --host {{ ansible_ssh_host }} --eval ' '"
changed_when: False
- name: Add admin user
mongodb_user:
login_host: "{{ ansible_host }}"
database: admin
name: root
password: "{{ ceilometer_container_db_password }}"
roles: 'root'
state: present
ignore_errors: True
- name: Add ceilometer database user
mongodb_user:
login_host: "{{ ansible_host }}"
login_user: "root"
login_password: "{{ ceilometer_container_db_password }}"
database: "ceilometer"
name: "{{ ceilometer_database_user }}"
password: "{{ ceilometer_container_db_password }}"
roles: 'readWrite,dbAdmin'
state: present
vars:
packages_mongodb:
- mongodb-clients
- mongodb-server
- python-pymongo
ceilometer_database_name: ceilometer
ceilometer_database_user: ceilometer