├── ansible.cfg ├── vars ├── RedHat.yml └── main.yml ├── templates ├── mongodb.repo.j2 └── mongod.conf.j2 ├── handlers └── main.yml ├── test.yml ├── tasks ├── setup-RedHat.yml ├── hugepages.yml ├── main.yml └── configure.yml ├── meta └── main.yml ├── defaults └── main.yml ├── files └── disable-transparent-hugepages └── README.md /ansible.cfg: -------------------------------------------------------------------------------- 1 | [defaults] 2 | roles_path = ../ 3 | -------------------------------------------------------------------------------- /vars/RedHat.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # vars file for RedHat 3 | -------------------------------------------------------------------------------- /vars/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # vars file for mongodb 3 | -------------------------------------------------------------------------------- /templates/mongodb.repo.j2: -------------------------------------------------------------------------------- 1 | [mongodb] 2 | name=MongoDB Repository 3 | baseurl={{ mongodb_baseurl }} 4 | gpgcheck=0 5 | enabled=1 6 | -------------------------------------------------------------------------------- /handlers/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # handlers file for mongodb 3 | 4 | - name: mongodb restart 5 | service: name={{ mongodb_daemon_name }} state=restarted 6 | -------------------------------------------------------------------------------- /test.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # test file 3 | 4 | - name: Install MongoDB. 5 | hosts: servers 6 | roles: 7 | - role: ansible-role-mongodb 8 | mongodb_conf_dbpath: /data/mongodb 9 | -------------------------------------------------------------------------------- /tasks/setup-RedHat.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # tasks file for RedHat 3 | 4 | - name: RedHat | Add source sources 5 | template: src=mongodb.repo.j2 dest=/etc/yum.repos.d/mongodb.repo 6 | 7 | - name: RedHat | Install Packages 8 | yum: name={{ item }} state=installed 9 | with_items: mongodb_packages 10 | -------------------------------------------------------------------------------- /meta/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | galaxy_info: 3 | author: z 4 | description: Install and configure the MongoDB 5 | company: 6 | license: license (BSD, MIT) 7 | min_ansible_version: 1.8 8 | platforms: 9 | - name: EL 10 | versions: 11 | - 6 12 | - 7 13 | categories: 14 | - database 15 | - database:nosql 16 | dependencies: [] 17 | -------------------------------------------------------------------------------- /tasks/hugepages.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # tasks file for hugepages 3 | 4 | - name: Disable Transparent Huge Pages. 5 | copy: src=disable-transparent-hugepages dest=/etc/init.d/disable-transparent-hugepages owner=root group=root mode=0755 6 | 7 | - name: Ensure Disable Transparent Huge Pages service is started and enabled at boot 8 | service: name=disable-transparent-hugepages state=started enabled=yes 9 | -------------------------------------------------------------------------------- /tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # tasks file for mongodb 3 | 4 | # Variable setup. 5 | - name: Include OS-specific variables. 6 | include_vars: "{{ ansible_os_family }}.yml" 7 | 8 | # Setup/install tasks. 9 | - include: setup-RedHat.yml 10 | when: ansible_os_family == 'RedHat' 11 | 12 | # Configure Transparent Huge Pages. 13 | - include: hugepages.yml 14 | when: mongodb_disable_thp 15 | 16 | # Configure MongoDB. 17 | - include: configure.yml 18 | -------------------------------------------------------------------------------- /tasks/configure.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # tasks for mongodb Configure 3 | 4 | - name: Create the data directory for the mongodb. 5 | file: path={{ mongodb_conf_dbpath }} owner={{ mongodb_user }} group={{ mongodb_user }} state=directory 6 | 7 | - name: Create the log directory for the mongodb. 8 | file: path={{ mongodb_conf_logpath }} owner={{ mongodb_user }} group={{ mongodb_user }} state=directory 9 | 10 | - name: Configure mongodb. 11 | template: src=mongod.conf.j2 dest=/etc/mongod.conf owner=root group=root mode=0644 12 | notify: mongodb restart 13 | 14 | - name: Ensure mongodb service is started and enabled at boot. 15 | service: name={{ mongodb_daemon_name}} state=started enabled=yes 16 | -------------------------------------------------------------------------------- /defaults/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # defaults file for mongodb 3 | 4 | mongodb_baseurl: "http://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.0/x86_64/" 5 | # MongoDB Repository baseurl 6 | # defaults is versions 3.0 7 | # versions 2.6 is "http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/" 8 | 9 | mongodb_disable_thp: true 10 | mongodb_packages: mongodb-org 11 | 12 | mongodb_user: mongod 13 | mongodb_daemon_name: "{{ 'mongod' if ('mongodb-org' in mongodb_packages) else 'mongodb' }}" 14 | 15 | mongodb_conf_logpath: "/var/log/mongodb" 16 | mongodb_conf_port: 27017 17 | mongodb_conf_dbpath: "/var/lib/mongo" 18 | mongodb_conf_pidfilepath: "/var/run/mongodb/mongod.pid" 19 | mongodb_conf_bind_ip: "127.0.0.1" 20 | mongodb_conf_auth: false 21 | 22 | mongodb_conf_replSet: "" 23 | mongodb_conf_oplogSize: 1024 24 | mongodb_conf_keyFile: "/path/to/keyfile" 25 | -------------------------------------------------------------------------------- /files/disable-transparent-hugepages: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ### BEGIN INIT INFO 3 | # Provides: disable-transparent-hugepages 4 | # Required-Start: $local_fs 5 | # Required-Stop: 6 | # X-Start-Before: mongod mongodb-mms-automation-agent 7 | # Default-Start: 2 3 4 5 8 | # Default-Stop: 0 1 6 9 | # Short-Description: Disable Linux transparent huge pages 10 | # Description: Disable Linux transparent huge pages, to improve 11 | # database performance. 12 | ### END INIT INFO 13 | 14 | case $1 in 15 | start) 16 | if [ -d /sys/kernel/mm/transparent_hugepage ]; then 17 | thp_path=/sys/kernel/mm/transparent_hugepage 18 | elif [ -d /sys/kernel/mm/redhat_transparent_hugepage ]; then 19 | thp_path=/sys/kernel/mm/redhat_transparent_hugepage 20 | else 21 | return 0 22 | fi 23 | 24 | echo 'never' > ${thp_path}/enabled 25 | echo 'never' > ${thp_path}/defrag 26 | 27 | unset thp_path 28 | ;; 29 | esac 30 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Ansible Role: mongodb 2 | 3 | Installs and configures the MongoDB. 4 | 5 | ## Requirements 6 | 7 | None. 8 | 9 | ## Role Variables 10 | 11 | ### `defaults/main.yml` 12 | 13 | * `mongodb_baseurl: "http://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.0/x86_64/"` 14 | * `mongodb_disable_thp: true` 15 | * `mongodb_packages: mongodb-org` 16 | * `mongodb_user: mongod` 17 | * `mongodb_daemon_name: "{{ 'mongod' if ('mongodb-org' in mongodb_packages) else 'mongodb' }}"` 18 | * `mongodb_conf_logpath: "/var/log/mongodb"` 19 | * `mongodb_conf_port: 27017` 20 | * `mongodb_conf_dbpath: "/var/lib/mongo"` 21 | * `mongodb_conf_pidfilepath: "/var/run/mongodb/mongod.pid"` 22 | * `mongodb_conf_bind_ip: "127.0.0.1"` 23 | * `mongodb_conf_auth: false` 24 | * `mongodb_conf_replSet: ""` 25 | * `mongodb_conf_oplogSize: 1024` 26 | * `mongodb_conf_keyFile: "/path/to/keyfile"` 27 | 28 | ## Dependencies 29 | 30 | None. 31 | 32 | ## Example Playbook 33 | 34 | - hosts: servers 35 | roles: 36 | - role: mongodb 37 | mongodb_conf_bind_ip: '{{ ansible_default_ipv4.address }}' 38 | mongodb_conf_auth: true 39 | 40 | ## Author Information 41 | 42 | z 43 | -------------------------------------------------------------------------------- /templates/mongod.conf.j2: -------------------------------------------------------------------------------- 1 | # mongod.conf 2 | 3 | #where to log 4 | logpath={{ mongodb_conf_logpath }}/{{ mongodb_daemon_name }}.log 5 | 6 | logappend=true 7 | 8 | # fork and run in background 9 | fork=true 10 | 11 | port={{ mongodb_conf_port }} 12 | 13 | dbpath={{ mongodb_conf_dbpath }} 14 | 15 | # location of pidfile 16 | pidfilepath={{ mongodb_conf_pidfilepath }} 17 | 18 | # Listen to local interface only. Comment out to listen on all interfaces. 19 | bind_ip={{ mongodb_conf_bind_ip }} 20 | 21 | # Disables write-ahead journaling 22 | # nojournal=true 23 | 24 | # Enables periodic logging of CPU utilization and I/O wait 25 | #cpu=true 26 | 27 | # Turn on/off security. Off is currently the default 28 | #noauth=true 29 | #auth=true 30 | {% if mongodb_conf_auth %} 31 | auth={{ mongodb_conf_auth | to_nice_json }} 32 | {% endif %} 33 | 34 | # Verbose logging output. 35 | #verbose=true 36 | 37 | # Inspect all client data for validity on receipt (useful for 38 | # developing drivers) 39 | #objcheck=true 40 | 41 | # Enable db quota management 42 | #quota=true 43 | 44 | # Set oplogging level where n is 45 | # 0=off (default) 46 | # 1=W 47 | # 2=R 48 | # 3=both 49 | # 7=W+some reads 50 | #diaglog=0 51 | 52 | # Ignore query hints 53 | #nohints=true 54 | 55 | # Enable the HTTP interface (Defaults to port 28017). 56 | #httpinterface=true 57 | 58 | # Turns off server-side scripting. This will result in greatly limited 59 | # functionality 60 | #noscripting=true 61 | 62 | # Turns off table scans. Any query that would do a table scan fails. 63 | #notablescan=true 64 | 65 | # Disable data file preallocation. 66 | #noprealloc=true 67 | 68 | # Specify .ns file size for new databases. 69 | # nssize= 70 | 71 | {% if mongodb_conf_replSet %} 72 | # Replication Options 73 | 74 | # in replicated mongo databases, specify the replica set name here 75 | replSet={{ mongodb_conf_replSet }} 76 | # maximum size in megabytes for replication operation log 77 | oplogSize={{ mongodb_conf_oplogSize }} 78 | # path to a key file storing authentication info for connections 79 | # between replica set members 80 | keyFile=/path/to/keyfile 81 | {% endif %} 82 | --------------------------------------------------------------------------------