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

71 lines
2.1 KiB
YAML

---
# Copyright 2016, Internap 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: Playbook for deploying MongoDB
hosts: service_all
user: root
gather_facts: true
pre_tasks:
- name: Install MongoDB packages
apt:
name: "{{ item }}"
state: present
with_items: "{{ packages_mongodb }}"
- name: Configure the MongoDB bind address
lineinfile:
dest: /etc/mongodb.conf
regexp: "^(#)?bind_ip"
line: "bind_ip = 10.100.100.2"
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 is changed
register: mongodb_restart
- name: Wait for mongodb to come back online after the restart
wait_for:
host: "10.100.100.2"
port: 27017
delay: 5
timeout: 30
when:
- mongodb_restart is defined
- mongodb_restart is changed
- name: Test mongodb connectivity
command: "mongo --host 10.100.100.2 --eval ' '"
changed_when: False
- name: Add almanach database user
mongodb_user:
login_host: "10.100.100.2"
database: admin
name: almanach
password: secrete
roles: 'readWrite,dbAdmin'
state: present
no_log: true
vars:
packages_mongodb:
- mongodb-clients
- mongodb-server
- python-pymongo