├── .dockerignore ├── .gitignore ├── LICENSE ├── README.md ├── Vagrantfile ├── circle.yml ├── defaults └── main.yml ├── files └── mongodb-org-3.0.repo ├── handlers └── main.yml ├── meta └── main.yml ├── tasks ├── install-gosu.yml ├── main.yml ├── set-role-variables.yml ├── use-apt.yml └── use-yum.yml ├── templates ├── mongod.upstart.ubuntu.conf.j2 ├── mongos.conf.j2 ├── mongos.sysvinit.debian.sh.j2 ├── mongos.sysvinit.gosu.redhat.sh.j2 └── mongos.upstart.ubuntu.conf.j2 ├── test.yml └── test ├── Dockerfile-centos6 ├── Dockerfile-centos7 ├── Dockerfile-debian7 ├── Dockerfile-debian8 ├── Dockerfile-ubuntu12.04 ├── Dockerfile-ubuntu14.04 └── mongod.conf.j2 /.dockerignore: -------------------------------------------------------------------------------- 1 | .git 2 | .vagrant 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .vagrant 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 William Yeh 4 | 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | williamyeh.mongodb for Ansible Galaxy 3 | ============ 4 | 5 | 6 | [![Circle CI](https://circleci.com/gh/William-Yeh/ansible-mongodb.svg?style=shield)](https://circleci.com/gh/William-Yeh/ansible-mongodb) 7 | 8 | 9 | ## Summary 10 | 11 | Role name in Ansible Galaxy: **[williamyeh.mongodb](https://galaxy.ansible.com/williamyeh/mongodb/)** 12 | 13 | This Ansible role has the following features for MongoDB: 14 | 15 | - Install specific version; 16 | - Handlers for restart/reload/stop events; 17 | - Bare bone configuration (*real* configuration should be left to user's template files; see **Usage** section below). 18 | 19 | 20 | 21 | 22 | ## Role Variables 23 | 24 | ### Mandatory variables 25 | 26 | None. 27 | 28 | 29 | 30 | 31 | ### Optional variables 32 | 33 | User-configurable defaults: 34 | 35 | ```yaml 36 | # MongoDB version; e.g., "3.0.4" 37 | # Will install the default (usually the latest stable) version, if not specified. 38 | mongodb_version 39 | 40 | 41 | # which components to install? 42 | # possible values: 43 | # - "mongod" 44 | # - "mongos" 45 | mongodb_components: [ "mongod" ] 46 | 47 | 48 | # install mongod as a config server? 49 | mongodb_configsvr: false 50 | 51 | # TCP port of config server 52 | mongodb_configsvr_port: 27019 53 | 54 | 55 | 56 | # use `service` command to start/restart mongodb daemon? 57 | mongodb_use_service: True 58 | ``` 59 | 60 | 61 | User-installable configuration files (by Ansible's template system): 62 | 63 | ```yaml 64 | # mongod conf template to be installed to "/etc/mongod.conf"; 65 | # relative to `playbook_dir` 66 | mongodb_mongod_conf 67 | 68 | # mongos conf template to be installed to "/etc/mongos.conf"; 69 | # relative to `playbook_dir` 70 | mongodb_mongos_conf 71 | 72 | ``` 73 | 74 | 75 | 76 | 77 | ## Handlers 78 | 79 | **mongod**: 80 | 81 | - `restart mongod` 82 | - `reload mongod` 83 | - `stop mongod` 84 | 85 | 86 | **mongos**: 87 | 88 | - `restart mongos` 89 | - `reload mongos` 90 | - `stop mongos` 91 | 92 | 93 | 94 | 95 | ## Usage 96 | 97 | 98 | ### Step 1: add role 99 | 100 | Add role name `williamyeh.mongodb` to your playbook file. 101 | 102 | 103 | ### Step 2: add variables 104 | 105 | Set vars in your playbook file. 106 | 107 | Simple example: 108 | 109 | ```yaml 110 | --- 111 | # file: simple-playbook.yml 112 | 113 | - hosts: all 114 | 115 | roles: 116 | - williamyeh.mongodb 117 | 118 | vars: 119 | mongodb_version: 3.0.4 120 | ``` 121 | 122 | 123 | ### Step 3: copy user's config files, if necessary 124 | 125 | 126 | More practical example: 127 | 128 | ```yaml 129 | --- 130 | # file: complex-playbook.yml 131 | 132 | - hosts: all 133 | 134 | roles: 135 | - williamyeh.mongodb 136 | 137 | vars: 138 | mongodb_version: 3.0.4 139 | 140 | mongodb_mongod_conf: "templates/mongod.conf.j2" 141 | 142 | ``` 143 | 144 | 145 | ## Dependencies 146 | 147 | None. 148 | 149 | 150 | ## License 151 | 152 | MIT License. See the [LICENSE file](LICENSE) for details. 153 | 154 | 155 | ## History 156 | 157 | Rewritten from my pre-Galaxy version: [server-config-template](https://github.com/William-Yeh/server-config-template). 158 | -------------------------------------------------------------------------------- /Vagrantfile: -------------------------------------------------------------------------------- 1 | Vagrant.configure("2") do |config| 2 | 3 | # main & default: normal OS series... 4 | config.vm.define "main", primary: true do |node| 5 | node.vm.box = "ubuntu/trusty64" 6 | #node.vm.box = "ubuntu/precise64" 7 | ###node.vm.box = "debian/jessie64" 8 | #node.vm.box = "debian/wheezy64" 9 | #node.vm.box = "bento/centos-7.2" 10 | #node.vm.box = "bento/centos-6.7" 11 | 12 | node.vm.provision "ansible" do |ansible| 13 | ansible.playbook = "test.yml" 14 | ansible.sudo = true 15 | end 16 | end 17 | 18 | 19 | # docker: for auto build & testing (e.g., Travis CI) 20 | config.vm.define "docker" do |node| 21 | node.vm.box = "williamyeh/ubuntu-trusty64-docker" 22 | 23 | node.vm.provision "shell", inline: <<-SHELL 24 | cd /vagrant 25 | docker build -f test/Dockerfile-ubuntu14.04 -t mongodb_trusty . 26 | docker build -f test/Dockerfile-ubuntu12.04 -t mongodb_precise . 27 | ###docker build -f test/Dockerfile-debian8 -t mongodb_jessie . 28 | docker build -f test/Dockerfile-debian7 -t mongodb_wheezy . 29 | docker build -f test/Dockerfile-centos7 -t mongodb_centos7 . 30 | docker build -f test/Dockerfile-centos6 -t mongodb_centos6 . 31 | SHELL 32 | end 33 | 34 | end 35 | -------------------------------------------------------------------------------- /circle.yml: -------------------------------------------------------------------------------- 1 | machine: 2 | services: 3 | - docker 4 | 5 | dependencies: 6 | override: 7 | - docker info 8 | - docker version 9 | 10 | - docker build -f test/Dockerfile-ubuntu14.04 -t mongodb_trusty . 11 | - docker build -f test/Dockerfile-ubuntu12.04 -t mongodb_precise . 12 | ###- docker build -f test/Dockerfile-debian8 -t mongodb_jessie . 13 | - docker build -f test/Dockerfile-debian7 -t mongodb_wheezy . 14 | - docker build -f test/Dockerfile-centos7 -t mongodb_centos7 . 15 | - docker build -f test/Dockerfile-centos6 -t mongodb_centos6 . 16 | 17 | test: 18 | override: 19 | - docker run -d --name c1 mongodb_trusty 20 | - IP=$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' c1) ; echo $IP > hostip 21 | - cat hostip | xargs -t -n 1 docker run -i mongodb_trusty mongo --eval "printjson(db.stats())" --host > result-ubuntu14.04 22 | 23 | - docker run -d --name c2 mongodb_precise 24 | - IP=$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' c2) ; echo $IP > hostip 25 | - cat hostip | xargs -t -n 1 docker run -i mongodb_precise mongo --eval "printjson(db.stats())" --host > result-ubuntu12.04 26 | 27 | #- docker run -d --name c3 mongodb_jessie 28 | #- IP=$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' c3) ; echo $IP > hostip 29 | #- cat hostip | xargs -t -n 1 docker run -i mongodb_jessie mongo --eval "printjson(db.stats())" --host > result-debian8 30 | 31 | - docker run -d --name c4 mongodb_wheezy 32 | - IP=$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' c4) ; echo $IP > hostip 33 | - cat hostip | xargs -t -n 1 docker run -i mongodb_wheezy mongo --eval "printjson(db.stats())" --host > result-debian7 34 | 35 | - docker run -d --name c5 mongodb_centos7 36 | - IP=$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' c5) ; echo $IP > hostip 37 | - cat hostip | xargs -t -n 1 docker run -i mongodb_centos7 mongo --eval "printjson(db.stats())" --host > result-centos7 38 | 39 | - docker run -d --name c6 mongodb_centos6 40 | - IP=$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' c6) ; echo $IP > hostip 41 | - cat hostip | xargs -t -n 1 docker run -i mongodb_centos6 mongo --eval "printjson(db.stats())" --host > result-centos6 42 | 43 | 44 | - echo "==> Validating the test results..." 45 | - grep 'storageSize' result-ubuntu14.04 46 | - grep 'storageSize' result-ubuntu12.04 47 | ###- grep 'storageSize' result-debian8 48 | - grep 'storageSize' result-debian7 49 | - grep 'storageSize' result-centos7 50 | - grep 'storageSize' result-centos6 51 | -------------------------------------------------------------------------------- /defaults/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | # 4 | # variables needed to be defined in user's playbook 5 | # 6 | 7 | 8 | 9 | # 10 | # user-configurable defaults 11 | # 12 | 13 | 14 | #mongodb_version: 3.0.4 # will install the default (usually the latest stable) version, if not specified. 15 | 16 | 17 | # which components to install? 18 | # possible values: 19 | # - "mongod" 20 | # - "mongos" 21 | mongodb_components: [ "mongod" ] 22 | 23 | 24 | mongodb_configsvr: false # install mongod as a config server? 25 | 26 | mongodb_configsvr_port: 27019 # TCP port of config server 27 | 28 | 29 | 30 | 31 | gosu_version: 1.7 32 | 33 | 34 | #---- the following vars are handled in tasks/set-role-variables.yml ------ 35 | 36 | #mongodb_use_service: True # use "service" command to start/restart mongodb? 37 | 38 | #mongodb_in_selinux: False 39 | -------------------------------------------------------------------------------- /files/mongodb-org-3.0.repo: -------------------------------------------------------------------------------- 1 | [mongodb-org-3.0] 2 | name=MongoDB Repository 3 | baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.0/x86_64/ 4 | gpgcheck=0 5 | enabled=1 -------------------------------------------------------------------------------- /handlers/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # file: handlers/main.yml 3 | # 4 | 5 | - name: restart mongod 6 | service: name=mongod state=restarted 7 | when: mongodb_use_service|bool 8 | 9 | - name: reload mongodb 10 | service: name=mongodb state=reloaded 11 | when: mongodb_use_service|bool 12 | 13 | - name: stop mongod 14 | service: name=mongod state=stopped 15 | when: mongodb_use_service|bool 16 | 17 | 18 | 19 | - name: restart mongos 20 | service: name=mongos state=restarted 21 | when: mongodb_use_service|bool 22 | 23 | - name: reload mongods 24 | service: name=mongods state=reloaded 25 | when: mongodb_use_service|bool 26 | 27 | - name: stop mongos 28 | service: name=mongos state=stopped 29 | when: mongodb_use_service|bool 30 | -------------------------------------------------------------------------------- /meta/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # nginx/meta/main.yml 3 | 4 | galaxy_info: 5 | author: williamyeh 6 | description: Install and configure MongoDB 7 | license: MIT 8 | 9 | min_ansible_version: 2.0.0 10 | 11 | platforms: 12 | - name: Ubuntu 13 | versions: 14 | - precise 15 | - trusty 16 | - name: Debian 17 | versions: 18 | #- jessie 19 | - wheezy 20 | - name: EL 21 | versions: 22 | - 6 23 | - 7 24 | galaxy_tags: 25 | - database 26 | - nosql 27 | - mongodb 28 | 29 | dependencies: [] 30 | -------------------------------------------------------------------------------- /tasks/install-gosu.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # file: tasks/install-gosu.yml 3 | # 4 | # Install "gosu" utility. 5 | # 6 | # @see https://github.com/tianon/gosu 7 | # 8 | 9 | 10 | - name: set internal variables for convenience 11 | set_fact: 12 | gosu_exe_url: "https://github.com/tianon/gosu/releases/download/{{ gosu_version }}/gosu-amd64" 13 | when: ansible_userspace_bits == "64" 14 | 15 | - name: set internal variables for convenience 16 | set_fact: 17 | gosu_exe_url: "https://github.com/tianon/gosu/releases/download/{{ gosu_version }}/gosu-i386" 18 | when: ansible_userspace_bits == "32" 19 | 20 | 21 | 22 | - name: download gosu executable 23 | get_url: url="{{ gosu_exe_url }}" dest="/usr/local/bin/gosu" 24 | 25 | - name: add executable permission 26 | file: path="/usr/local/bin/gosu" state=file mode="a+x" 27 | -------------------------------------------------------------------------------- /tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # file: tasks/main.yml 3 | # Top-level installer for MongoDB. 4 | # 5 | # @see http://docs.mongodb.org/manual/administration/install-on-linux/ 6 | # 7 | 8 | - name: set role variables, if necessary 9 | include: set-role-variables.yml 10 | 11 | 12 | - name: install libselinux-python binary for Ansible to work 13 | yum: name=libselinux-python state=present 14 | when: ansible_pkg_mgr == "yum" 15 | 16 | #- name: delegate to SELINUX handling subtask, if necessary 17 | # include: set-selinux.yml 18 | # when: mongodb_in_selinux is defined and mongodb_in_selinux == true 19 | 20 | 21 | 22 | - name: delegate to APT system for installation 23 | include: use-apt.yml 24 | when: ansible_pkg_mgr == "apt" 25 | 26 | - name: delegate to YUM system for installation 27 | include: use-yum.yml 28 | when: ansible_pkg_mgr == "yum" 29 | 30 | 31 | # 32 | # config files: mongod 33 | # 34 | 35 | - name: copy mongod config file from playbook's, if any 36 | template: src={{ playbook_dir }}/{{ mongodb_mongod_conf }} dest=/etc/mongod.conf 37 | when: '("mongod" in mongodb_components) and (mongodb_mongod_conf is defined)' 38 | notify: 39 | - restart mongod 40 | 41 | # 42 | # config files: mongos 43 | # 44 | 45 | - name: copy mongos config file from playbook's, if any 46 | template: src={{ playbook_dir }}/{{ mongodb_mongos_conf }} dest=/etc/mongos.conf 47 | when: '("mongos" in mongodb_components) and (mongodb_mongos_conf is defined)' 48 | notify: 49 | - restart mongos 50 | 51 | - name: copy mongos config file from role's default, if necessary 52 | template: src=../templates/mongos.conf.j2 dest=/etc/mongos.conf 53 | when: '("mongos" in mongodb_components) and (mongodb_mongos_conf is not defined)' 54 | notify: 55 | - restart mongos 56 | -------------------------------------------------------------------------------- /tasks/set-role-variables.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # file: tasks/set-role-variables.yml 3 | # set necessary role variables. 4 | # 5 | 6 | - name: set mongodb_use_service = True, if not defined 7 | set_fact: 8 | mongodb_use_service: True 9 | when: mongodb_use_service is not defined 10 | 11 | 12 | 13 | #- name: set mongodb_in_selinux = True for CentOS 6 14 | # set_fact: 15 | # mongodb_in_selinux: True 16 | # when: mongodb_in_selinux is not defined and ansible_distribution|lower == "centos" and ansible_distribution_major_version == "6" 17 | # 18 | #- name: set mongodb_in_selinux = True for RHEL 6 19 | # set_fact: 20 | # mongodb_in_selinux: True 21 | # when: mongodb_in_selinux is not defined and ansible_distribution == "Red Hat Enterprise Linux" and ansible_distribution_major_version == "6" 22 | # 23 | #- name: set mongodb_in_selinux = True, judging from the context 24 | # set_fact: 25 | # mongodb_in_selinux: True 26 | # when: mongodb_in_selinux is not defined and ansible_selinux == true or (ansible_selinux.status is defined and ansible_selinux.status == "enabled") 27 | # -------------------------------------------------------------------------------- /tasks/use-apt.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # file: tasks/use-apt.yml 3 | # 4 | # Configure mongodb from APT repository. 5 | # 6 | # @see http://wiki.mongodb.org/Install 7 | # @see http://mongodb.org/packages/ubuntu/dists/ 8 | # @see http://mongodb.org/packages/debian/dists/ 9 | # 10 | 11 | - name: install add-apt-repository binary for Ansible to work 12 | apt: name={{ item }} state=present update_cache=yes 13 | with_items: 14 | - python-software-properties 15 | - apt-transport-https 16 | 17 | 18 | 19 | - name: add MongoDB public GPG key 20 | apt_key: url=https://docs.mongodb.org/10gen-gpg-key.asc id=7F0CEB10 state=present validate_certs=False 21 | 22 | - name: add MongoDB stable repository (for Ubuntu) 23 | apt_repository: repo='deb http://repo.mongodb.org/apt/{{ ansible_distribution|lower }} {{ ansible_distribution_release|lower }}/mongodb-org/3.0 multiverse' state=present 24 | when: ansible_distribution == "Ubuntu" 25 | 26 | - name: add MongoDB stable repository (for Debian) 27 | apt_repository: repo='deb http://repo.mongodb.org/apt/{{ ansible_distribution|lower }} {{ ansible_distribution_release|lower }}/mongodb-org/3.0 main' state=present 28 | when: ansible_distribution == "Debian" 29 | 30 | - name: run the equivalent of "apt-get update" as a separate step 31 | apt: update_cache=yes 32 | 33 | 34 | - block: 35 | - name: install MongoDB with specific version 36 | apt: name="mongodb-org={{ mongodb_version }}*" state=present force=yes 37 | 38 | - apt: name="mongodb-org-shell={{ mongodb_version }}*" state=present force=yes 39 | - apt: name="mongodb-org-tools={{ mongodb_version }}*" state=present force=yes 40 | 41 | when: mongodb_version is defined 42 | 43 | - name: install MongoDB with default version 44 | apt: name=mongodb-org state=present force=yes 45 | when: mongodb_version is not defined 46 | 47 | 48 | 49 | # 50 | # INIT system for mongod 51 | # 52 | 53 | - name: set mongod INIT status and start 54 | service: name=mongod state=started enabled=yes 55 | when: '"mongod" in mongodb_components' 56 | 57 | - name: unset mongod INIT status and stop, if necessary 58 | service: name=mongod state=stopped enabled=no 59 | ignore_errors: yes 60 | when: '"mongod" not in mongodb_components' 61 | 62 | 63 | # 64 | # INIT system for mongos 65 | # 66 | 67 | - name: copy mongos INIT script to server (Ubuntu) 68 | template: src="../templates/mongos.upstart.ubuntu.conf.j2" dest="/etc/init/mongos.conf" 69 | when: '("mongos" in mongodb_components) and (ansible_distribution == "Ubuntu")' 70 | 71 | - name: copy mongos INIT script to server (Debian) 72 | template: src="../templates/mongos.sysvinit.debian.sh.j2" dest="/etc/init.d/mongos" mode="a+x" 73 | when: '("mongos" in mongodb_components) and (ansible_distribution == "Debian")' 74 | 75 | - name: set mongos INIT status (SysV style) 76 | shell: update-rc.d mongos defaults 77 | when: '("mongos" in mongodb_components) and (ansible_distribution == "Debian")' 78 | 79 | - name: set mongos INIT status 80 | service: name=mongos enabled=yes 81 | when: '"mongos" in mongodb_components' 82 | -------------------------------------------------------------------------------- /tasks/use-yum.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # file: tasks/use-yum.yml 3 | # 4 | # Configure mongodb from YUM repository. 5 | # 6 | # @see http://docs.mongodb.org/manual/tutorial/install-mongodb-on-red-hat/ 7 | # 8 | 9 | #- name: install libselinux-python binary for Ansible to work 10 | # yum: name=libselinux-python state=present 11 | 12 | 13 | 14 | - name: add MongoDB official repository for CentOS 15 | copy: src=../files/mongodb-org-3.0.repo dest=/etc/yum.repos.d/mongodb-org-3.0.repo 16 | 17 | 18 | - block: 19 | - name: install MongoDB with specific version 20 | yum: name="mongodb-org-{{ mongodb_version }}*" update_cache=yes state=present 21 | 22 | yum: name="mongodb-org-shell-{{ mongodb_version }}*" state=present 23 | yum: name="mongodb-org-tools-{{ mongodb_version }}*" state=present 24 | 25 | when: mongodb_version is defined 26 | 27 | - name: install MongoDB with default version 28 | yum: name=mongodb-org state=present 29 | when: mongodb_version is not defined 30 | 31 | 32 | - name: install gosu 33 | include: install-gosu.yml 34 | 35 | 36 | # 37 | # INIT system for mongod 38 | # 39 | 40 | - name: set mongod INIT status and start 41 | service: name=mongod state=started enabled=yes 42 | when: 'mongodb_use_service|bool and ("mongod" in mongodb_components)' 43 | 44 | - name: set mongod INIT status (SysV style) 45 | command: /sbin/chkconfig mongod on 46 | when: 'not mongodb_use_service|bool and ("mongod" in mongodb_components)' 47 | 48 | 49 | # 50 | # INIT system for mongos 51 | # 52 | 53 | - name: copy mongos INIT script to server 54 | template: src="../templates/mongos.sysvinit.gosu.redhat.sh.j2" dest="/etc/init.d/mongos" mode="a+x" 55 | when: '"mongos" in mongodb_components' 56 | 57 | - name: set mongos INIT status 58 | service: name=mongos enabled=yes 59 | when: 'mongodb_use_service|bool and ("mongos" in mongodb_components)' 60 | 61 | - name: set mongos INIT status (SysV style) 62 | command: /sbin/chkconfig mongos on 63 | when: 'not mongodb_use_service|bool and ("mongos" in mongodb_components)' 64 | -------------------------------------------------------------------------------- /templates/mongod.upstart.ubuntu.conf.j2: -------------------------------------------------------------------------------- 1 | # Ubuntu upstart file at /etc/init/mongod.conf 2 | 3 | # Recommended ulimit values for mongod or mongos 4 | # See http://docs.mongodb.org/manual/reference/ulimit/#recommended-settings 5 | # 6 | limit fsize unlimited unlimited 7 | limit cpu unlimited unlimited 8 | limit as unlimited unlimited 9 | limit nofile 64000 64000 10 | limit rss unlimited unlimited 11 | limit nproc 32000 32000 12 | 13 | kill timeout 300 # wait 300s between SIGTERM and SIGKILL. 14 | 15 | pre-start script 16 | DAEMONUSER=${DAEMONUSER:-mongodb} 17 | if [ ! -d /var/lib/mongod ]; then 18 | mkdir -p /var/lib/mongodb && chown mongodb:mongodb /var/lib/mongodb 19 | fi 20 | if [ ! -d /var/log/mongod ]; then 21 | mkdir -p /var/log/mongodb && chown mongodb:mongodb /var/log/mongodb 22 | fi 23 | touch /var/run/mongodb.pid 24 | chown $DAEMONUSER /var/run/mongodb.pid 25 | end script 26 | 27 | start on runlevel [2345] 28 | stop on runlevel [06] 29 | 30 | script 31 | ENABLE_MONGOD="yes" 32 | CONF=/etc/mongod.conf 33 | DAEMON=/usr/bin/mongod 34 | DAEMONUSER=${DAEMONUSER:-mongodb} 35 | 36 | if [ -f /etc/default/mongod ]; then . /etc/default/mongod; fi 37 | 38 | # Handle NUMA access to CPUs (SERVER-3574) 39 | # This verifies the existence of numactl as well as testing that the command works 40 | NUMACTL_ARGS="--interleave=all" 41 | if which numactl >/dev/null 2>/dev/null && numactl $NUMACTL_ARGS ls / >/dev/null 2>/dev/null 42 | then 43 | NUMACTL="$(which numactl) -- $NUMACTL_ARGS" 44 | DAEMON_OPTS=${DAEMON_OPTS:-"--config $CONF"} 45 | else 46 | NUMACTL="" 47 | DAEMON_OPTS="-- "${DAEMON_OPTS:-"--config $CONF"} 48 | fi 49 | 50 | if [ "x$ENABLE_MONGOD" = "xyes" ] 51 | then 52 | exec start-stop-daemon --start \ 53 | --chuid $DAEMONUSER \ 54 | --pidfile /var/run/mongodb.pid \ 55 | --make-pidfile \ 56 | --exec $NUMACTL $DAEMON $DAEMON_OPTS 57 | fi 58 | end script 59 | -------------------------------------------------------------------------------- /templates/mongos.conf.j2: -------------------------------------------------------------------------------- 1 | # mongos.conf 2 | # config for MongoDB routing server (mongos) 3 | 4 | configdb=configsvr.example.com:{{ mongodb_configsvr_port }} 5 | 6 | # HA setting 7 | #configdb=mongocfg-1:{{ mongodb_configsvr_port }},mongocfg-2:{{ mongodb_configsvr_port }},mongocfg-3:{{ mongodb_configsvr_port }} 8 | 9 | 10 | logpath=/var/log/mongodb/mongos.log 11 | logappend=true 12 | 13 | 14 | 15 | {% if ansible_os_family == "RedHat" %} 16 | 17 | # processManagement.pidFilePath required by /etc/init.d/mongo** 18 | # @see http://docs.mongodb.org/manual/reference/configuration-options/ 19 | pidfilepath=/var/run/mongodb/mongos.pid 20 | 21 | {% endif %} 22 | -------------------------------------------------------------------------------- /templates/mongos.sysvinit.debian.sh.j2: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # init.d script with LSB support. 4 | # 5 | # Copyright (c) 2007 Javier Fernandez-Sanguino 6 | # 7 | # This is free software; you may redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as 9 | # published by the Free Software Foundation; either version 2, 10 | # or (at your option) any later version. 11 | # 12 | # This is distributed in the hope that it will be useful, but 13 | # WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License with 18 | # the Debian operating system, in /usr/share/common-licenses/GPL; if 19 | # not, write to the Free Software Foundation, Inc., 59 Temple Place, 20 | # Suite 330, Boston, MA 02111-1307 USA 21 | # 22 | ### BEGIN INIT INFO 23 | # Provides: mongos 24 | # Required-Start: $network $local_fs $remote_fs 25 | # Required-Stop: $network $local_fs $remote_fs 26 | # Should-Start: $named 27 | # Should-Stop: 28 | # Default-Start: 2 3 4 5 29 | # Default-Stop: 0 1 6 30 | # Short-Description: An object/document-oriented database 31 | # Description: MongoDB is a high-performance, open source, schema-free 32 | # document-oriented data store that's easy to deploy, manage 33 | # and use. It's network accessible, written in C++ and offers 34 | # the following features: 35 | # 36 | # * Collection oriented storage - easy storage of object- 37 | # style data 38 | # * Full index support, including on inner objects 39 | # * Query profiling 40 | # * Replication and fail-over support 41 | # * Efficient storage of binary data including large 42 | # objects (e.g. videos) 43 | # * Automatic partitioning for cloud-level scalability 44 | # 45 | # High performance, scalability, and reasonable depth of 46 | # functionality are the goals for the project. 47 | ### END INIT INFO 48 | 49 | PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin 50 | DAEMON=/usr/bin/mongos 51 | DESC=database 52 | 53 | NAME=mongos 54 | # Defaults. Can be overridden by the /etc/default/$NAME 55 | # Other configuration options are located in $CONF file. See here for more: 56 | # http://dochub.mongodb.org/core/configurationoptions 57 | CONF=/etc/mongos.conf 58 | PIDFILE=/var/run/$NAME.pid 59 | ENABLE_MONGOD=yes 60 | 61 | # Include mongodb defaults if available 62 | if [ -f /etc/default/$NAME ] ; then 63 | . /etc/default/$NAME 64 | fi 65 | 66 | # Handle NUMA access to CPUs (SERVER-3574) 67 | # This verifies the existence of numactl as well as testing that the command works 68 | NUMACTL_ARGS="--interleave=all" 69 | if which numactl >/dev/null 2>/dev/null && numactl $NUMACTL_ARGS ls / >/dev/null 2>/dev/null 70 | then 71 | NUMACTL="`which numactl` -- $NUMACTL_ARGS" 72 | DAEMON_OPTS=${DAEMON_OPTS:-"--config $CONF"} 73 | else 74 | NUMACTL="" 75 | DAEMON_OPTS="-- "${DAEMON_OPTS:-"--config $CONF"} 76 | fi 77 | 78 | if test ! -x $DAEMON; then 79 | echo "Could not find $DAEMON" 80 | exit 0 81 | fi 82 | 83 | if test "x$ENABLE_MONGOD" != "xyes"; then 84 | exit 0 85 | fi 86 | 87 | . /lib/lsb/init-functions 88 | 89 | STARTTIME=1 90 | DIETIME=10 # Time to wait for the server to die, in seconds 91 | # If this value is set too low you might not 92 | # let some servers to die gracefully and 93 | # 'restart' will not work 94 | 95 | DAEMONUSER=${DAEMONUSER:-mongodb} 96 | 97 | set -e 98 | 99 | running_pid() { 100 | # Check if a given process pid's cmdline matches a given name 101 | pid=$1 102 | name=$2 103 | [ -z "$pid" ] && return 1 104 | [ ! -d /proc/$pid ] && return 1 105 | cmd=`cat /proc/$pid/cmdline | tr "\000" "\n"|head -n 1 |cut -d : -f 1` 106 | # Is this the expected server 107 | [ "$cmd" != "$name" ] && return 1 108 | return 0 109 | } 110 | 111 | running() { 112 | # Check if the process is running looking at /proc 113 | # (works for all users) 114 | 115 | # No pidfile, probably no daemon present 116 | [ ! -f "$PIDFILE" ] && return 1 117 | pid=`cat $PIDFILE` 118 | running_pid $pid $DAEMON || return 1 119 | return 0 120 | } 121 | 122 | start_server() { 123 | # Recommended ulimit values for mongod or mongos 124 | # See http://docs.mongodb.org/manual/reference/ulimit/#recommended-settings 125 | # 126 | ulimit -f unlimited 127 | ulimit -t unlimited 128 | ulimit -v unlimited 129 | ulimit -n 64000 130 | ulimit -m unlimited 131 | 132 | # In dash, ulimit takes -p for maximum user processes 133 | # In bash, it's -u 134 | if readlink /proc/$$/exe | grep -q dash 135 | then 136 | ulimit -p 64000 137 | else 138 | ulimit -u 64000 139 | fi 140 | 141 | # Start the process using the wrapper 142 | start-stop-daemon --background --start --quiet --pidfile $PIDFILE \ 143 | --make-pidfile --chuid $DAEMONUSER \ 144 | --exec $NUMACTL $DAEMON $DAEMON_OPTS 145 | errcode=$? 146 | return $errcode 147 | } 148 | 149 | stop_server() { 150 | # Stop the process using the wrapper 151 | start-stop-daemon --stop --quiet --pidfile $PIDFILE \ 152 | --retry 300 \ 153 | --user $DAEMONUSER \ 154 | --exec $DAEMON 155 | errcode=$? 156 | return $errcode 157 | } 158 | 159 | force_stop() { 160 | # Force the process to die killing it manually 161 | [ ! -e "$PIDFILE" ] && return 162 | if running ; then 163 | kill -15 $pid 164 | # Is it really dead? 165 | sleep "$DIETIME"s 166 | if running ; then 167 | kill -9 $pid 168 | sleep "$DIETIME"s 169 | if running ; then 170 | echo "Cannot kill $NAME (pid=$pid)!" 171 | exit 1 172 | fi 173 | fi 174 | fi 175 | rm -f $PIDFILE 176 | } 177 | 178 | 179 | case "$1" in 180 | start) 181 | log_daemon_msg "Starting $DESC" "$NAME" 182 | # Check if it's running first 183 | if running ; then 184 | log_progress_msg "apparently already running" 185 | log_end_msg 0 186 | exit 0 187 | fi 188 | if start_server ; then 189 | # NOTE: Some servers might die some time after they start, 190 | # this code will detect this issue if STARTTIME is set 191 | # to a reasonable value 192 | [ -n "$STARTTIME" ] && sleep $STARTTIME # Wait some time 193 | if running ; then 194 | # It's ok, the server started and is running 195 | log_end_msg 0 196 | else 197 | # It is not running after we did start 198 | log_end_msg 1 199 | fi 200 | else 201 | # Either we could not start it 202 | log_end_msg 1 203 | fi 204 | ;; 205 | stop) 206 | log_daemon_msg "Stopping $DESC" "$NAME" 207 | if running ; then 208 | # Only stop the server if we see it running 209 | errcode=0 210 | stop_server || errcode=$? 211 | log_end_msg $errcode 212 | else 213 | # If it's not running don't do anything 214 | log_progress_msg "apparently not running" 215 | log_end_msg 0 216 | exit 0 217 | fi 218 | ;; 219 | force-stop) 220 | # First try to stop gracefully the program 221 | $0 stop 222 | if running; then 223 | # If it's still running try to kill it more forcefully 224 | log_daemon_msg "Stopping (force) $DESC" "$NAME" 225 | errcode=0 226 | force_stop || errcode=$? 227 | log_end_msg $errcode 228 | fi 229 | ;; 230 | restart|force-reload) 231 | log_daemon_msg "Restarting $DESC" "$NAME" 232 | errcode=0 233 | stop_server || errcode=$? 234 | # Wait some sensible amount, some server need this 235 | [ -n "$DIETIME" ] && sleep $DIETIME 236 | start_server || errcode=$? 237 | [ -n "$STARTTIME" ] && sleep $STARTTIME 238 | running || errcode=$? 239 | log_end_msg $errcode 240 | ;; 241 | status) 242 | 243 | log_daemon_msg "Checking status of $DESC" "$NAME" 244 | if running ; then 245 | log_progress_msg "running" 246 | log_end_msg 0 247 | else 248 | log_progress_msg "apparently not running" 249 | log_end_msg 1 250 | exit 1 251 | fi 252 | ;; 253 | # MongoDB can't reload its configuration. 254 | reload) 255 | log_warning_msg "Reloading $NAME daemon: not implemented, as the daemon" 256 | log_warning_msg "cannot re-read the config file (use restart)." 257 | ;; 258 | 259 | *) 260 | N=/etc/init.d/$NAME 261 | echo "Usage: $N {start|stop|force-stop|restart|force-reload|status}" >&2 262 | exit 1 263 | ;; 264 | esac 265 | 266 | exit 0 267 | -------------------------------------------------------------------------------- /templates/mongos.sysvinit.gosu.redhat.sh.j2: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ### BEGIN INIT INFO 4 | # processname: mongos 5 | # Short-Description: MongoDB routing server. 6 | # Description: MongoDB is a high-performance, open source, schema-free 7 | # document-oriented data store. 8 | # 9 | # chkconfig: 2345 80 80 10 | # config: /etc/mongos.conf 11 | # pidfile: /var/run/mongodb/mongos.pid 12 | # 13 | # 14 | ### END INIT INFO 15 | 16 | #set -e 17 | 18 | # Source function library. 19 | . /etc/init.d/functions 20 | 21 | 22 | NAME=mongos 23 | DESC="MongoDB routing server" 24 | DAEMON=/usr/bin/mongos 25 | USER=mongod 26 | CONFIG=/etc/mongos.conf 27 | #PID=/var/run/mongodb/$NAME.pid 28 | PID=`awk -F'[:=]' -v IGNORECASE=1 '/^[[:blank:]]*(processManagement\.)?pidfilepath[[:blank:]]*[:=][[:blank:]]*/{print $2}' "$CONFIG" | tr -d "[:blank:]\"'"` 29 | #LOG=/var/log/mongodb/$NAME.log 30 | LOG=/dev/null 31 | GOSU=/usr/local/bin/gosu 32 | 33 | RETVAL=0 34 | 35 | 36 | 37 | DAEMON_OPTS="--config $CONFIG" 38 | 39 | 40 | 41 | 42 | # Check if DAEMON binary exist 43 | [ -f $DAEMON ] || exit 0 44 | 45 | [ -f "/etc/default/$NAME" ] && . /etc/default/$NAME 46 | 47 | 48 | service_not_configured () { 49 | if [ "$1" != "stop" ]; then 50 | printf "\tPlease configure $NAME and then edit /etc/default/$NAME\n" 51 | printf "\tand set the \"START\" variable to \"yes\" in order to allow\n" 52 | printf "\t$NAME to start.\n" 53 | fi 54 | exit 0 55 | } 56 | 57 | service_checks() { 58 | # Check if START variable is set to "yes", if not we exit. 59 | if [ "$START" != "yes" ]; then 60 | service_not_configured $1 61 | fi 62 | } 63 | 64 | start() { 65 | #service_checks $1 66 | 67 | # Recommended ulimit values for mongod or mongos 68 | # See http://docs.mongodb.org/manual/reference/ulimit/#recommended-settings 69 | # 70 | ulimit -f unlimited 71 | ulimit -t unlimited 72 | ulimit -v unlimited 73 | ulimit -n 64000 74 | ulimit -m unlimited 75 | ulimit -u 64000 76 | 77 | 78 | $GOSU $USER $DAEMON $DAEMON_OPTS > $LOG 2>&1 & 79 | RETVAL=$? 80 | #echo $! > $PID 81 | } 82 | 83 | stop() { 84 | killproc -p $PID -b $DAEMON $NAME 85 | RETVAL=$? 86 | } 87 | 88 | reload() { 89 | killproc -p $PID -b $DAEMON $NAME -HUP 90 | RETVAL=$? 91 | } 92 | 93 | case "$1" in 94 | start) 95 | echo -n $"Starting $DESC -" "$NAME" $'\n' 96 | start 97 | ;; 98 | 99 | stop) 100 | echo -n $"Stopping $DESC -" "$NAME" $'\n' 101 | stop 102 | ;; 103 | 104 | reload) 105 | echo -n $"Restarting $DESC -" "$NAME" $'\n' 106 | # MongoDB doesn't have a "reload" operation. 107 | # @see http://docs.mongodb.org/manual/tutorial/manage-mongodb-processes/ 108 | stop 109 | start 110 | #echo -n $"Reloading $DESC configuration -" "$NAME" $'\n' 111 | #reload 112 | ;; 113 | 114 | restart|force-reload) 115 | echo -n $"Restarting $DESC -" "$NAME" $'\n' 116 | stop 117 | start 118 | ;; 119 | 120 | syntax) 121 | $DAEMON --help 122 | ;; 123 | 124 | status) 125 | status -p $PID $DAEMON 126 | ;; 127 | 128 | *) 129 | echo -n $"Usage: /etc/init.d/$NAME {start|stop|reload|restart|force-reload|syntax|status}" $'\n' 130 | ;; 131 | esac 132 | 133 | exit $RETVAL 134 | -------------------------------------------------------------------------------- /templates/mongos.upstart.ubuntu.conf.j2: -------------------------------------------------------------------------------- 1 | # Ubuntu upstart file at /etc/init/mongos.conf 2 | 3 | # Recommended ulimit values for mongod or mongos 4 | # See http://docs.mongodb.org/manual/reference/ulimit/#recommended-settings 5 | # 6 | limit fsize unlimited unlimited 7 | limit cpu unlimited unlimited 8 | limit as unlimited unlimited 9 | limit nofile 64000 64000 10 | limit rss unlimited unlimited 11 | limit nproc 32000 32000 12 | 13 | kill timeout 300 # wait 300s between SIGTERM and SIGKILL. 14 | 15 | pre-start script 16 | DAEMONUSER=${DAEMONUSER:-mongodb} 17 | if [ ! -d /var/lib/mongod ]; then 18 | mkdir -p /var/lib/mongodb && chown mongodb:mongodb /var/lib/mongodb 19 | fi 20 | if [ ! -d /var/log/mongod ]; then 21 | mkdir -p /var/log/mongodb && chown mongodb:mongodb /var/log/mongodb 22 | fi 23 | touch /var/run/mongos.pid 24 | chown $DAEMONUSER /var/run/mongos.pid 25 | end script 26 | 27 | start on runlevel [2345] 28 | stop on runlevel [06] 29 | 30 | script 31 | ENABLE_MONGOD="yes" 32 | CONF=/etc/mongos.conf 33 | DAEMON=/usr/bin/mongos 34 | DAEMONUSER=${DAEMONUSER:-mongodb} 35 | 36 | if [ -f /etc/default/mongos ]; then . /etc/default/mongos; fi 37 | 38 | # Handle NUMA access to CPUs (SERVER-3574) 39 | # This verifies the existence of numactl as well as testing that the command works 40 | NUMACTL_ARGS="--interleave=all" 41 | if which numactl >/dev/null 2>/dev/null && numactl $NUMACTL_ARGS ls / >/dev/null 2>/dev/null 42 | then 43 | NUMACTL="$(which numactl) -- $NUMACTL_ARGS" 44 | DAEMON_OPTS=${DAEMON_OPTS:-"--config $CONF"} 45 | else 46 | NUMACTL="" 47 | DAEMON_OPTS="-- "${DAEMON_OPTS:-"--config $CONF"} 48 | fi 49 | 50 | if [ "x$ENABLE_MONGOD" = "xyes" ] 51 | then 52 | exec start-stop-daemon --start \ 53 | --chuid $DAEMONUSER \ 54 | --pidfile /var/run/mongos.pid \ 55 | --make-pidfile \ 56 | --exec $NUMACTL $DAEMON $DAEMON_OPTS 57 | fi 58 | end script 59 | -------------------------------------------------------------------------------- /test.yml: -------------------------------------------------------------------------------- 1 | - hosts: all 2 | become: True 3 | tasks: 4 | - include: 'tasks/main.yml' 5 | handlers: 6 | - include: 'handlers/main.yml' 7 | vars_files: 8 | - 'defaults/main.yml' 9 | 10 | vars: 11 | #mongodb_version: 1.8.0 12 | 13 | #mongodb_components: [ "mongod" ] 14 | #mongodb_components: [ "mongos" ] 15 | #mongodb_components: [ "mongod", "mongos" ] 16 | 17 | mongodb_mongod_conf: "test/mongod.conf.j2" 18 | #mongodb_configsvr: true 19 | -------------------------------------------------------------------------------- /test/Dockerfile-centos6: -------------------------------------------------------------------------------- 1 | # Dockerfile for building image that contains software stack provisioned by Ansible. 2 | # 3 | # Version 1.1 4 | # 5 | 6 | 7 | # pull base image 8 | FROM williamyeh/ansible:master-centos6-onbuild 9 | 10 | MAINTAINER William Yeh 11 | 12 | 13 | # 14 | # build phase 15 | # 16 | 17 | ENV PLAYBOOK test.yml 18 | RUN ansible-playbook-wrapper -vvv 19 | 20 | EXPOSE 27017 21 | 22 | 23 | # 24 | # test phase 25 | # 26 | 27 | RUN echo "===> Patch conf file to allow 0.0.0.0 and disable fork..." && \ 28 | sed -i -e 's/^\(\s*bind_ip\)/#--- \1/' /etc/mongod.conf && \ 29 | sed -i -e 's/^\(\s*fork\)/#--- \1/' /etc/mongod.conf 30 | 31 | 32 | CMD ["mongod", "--config", "/etc/mongod.conf"] 33 | -------------------------------------------------------------------------------- /test/Dockerfile-centos7: -------------------------------------------------------------------------------- 1 | # Dockerfile for building image that contains software stack provisioned by Ansible. 2 | # 3 | # Version 1.1 4 | # 5 | 6 | 7 | # pull base image 8 | FROM williamyeh/ansible:master-centos7-onbuild 9 | 10 | MAINTAINER William Yeh 11 | 12 | 13 | # 14 | # build phase 15 | # 16 | 17 | ENV PLAYBOOK test.yml 18 | RUN ansible-playbook-wrapper -vvv --extra-vars "mongodb_use_service=False" 19 | 20 | EXPOSE 27017 21 | 22 | 23 | # 24 | # test phase 25 | # 26 | 27 | RUN echo "===> Patch conf file to allow 0.0.0.0 and disable fork..." && \ 28 | sed -i -e 's/^\(\s*bind_ip\)/#--- \1/' /etc/mongod.conf && \ 29 | sed -i -e 's/^\(\s*fork\)/#--- \1/' /etc/mongod.conf 30 | 31 | 32 | CMD ["mongod", "--config", "/etc/mongod.conf"] 33 | -------------------------------------------------------------------------------- /test/Dockerfile-debian7: -------------------------------------------------------------------------------- 1 | # Dockerfile for building image that contains software stack provisioned by Ansible. 2 | # 3 | # Version 1.1 4 | # 5 | 6 | 7 | # pull base image 8 | FROM williamyeh/ansible:debian7-onbuild 9 | 10 | MAINTAINER William Yeh 11 | 12 | 13 | # 14 | # build phase 15 | # 16 | 17 | # install commands required in MongoDB installation package 18 | RUN DEBIAN_FRONTEND=noninteractive apt-get install -y adduser 19 | 20 | ENV PLAYBOOK test.yml 21 | RUN ansible-playbook-wrapper 22 | 23 | EXPOSE 27017 24 | 25 | 26 | # 27 | # test phase 28 | # 29 | 30 | RUN echo "===> Patch conf file to allow 0.0.0.0 and disable fork..." && \ 31 | sed -i -e 's/^\(\s*bind_ip\)/#--- \1/' /etc/mongod.conf && \ 32 | sed -i -e 's/^\(\s*fork\)/#--- \1/' /etc/mongod.conf 33 | 34 | 35 | CMD ["mongod", "--config", "/etc/mongod.conf"] 36 | -------------------------------------------------------------------------------- /test/Dockerfile-debian8: -------------------------------------------------------------------------------- 1 | # Dockerfile for building image that contains software stack provisioned by Ansible. 2 | # 3 | # Version 1.1 4 | # 5 | 6 | 7 | # pull base image 8 | FROM williamyeh/ansible:debian8-onbuild 9 | 10 | MAINTAINER William Yeh 11 | 12 | 13 | # 14 | # build phase 15 | # 16 | 17 | # install commands required in MongoDB installation package 18 | RUN DEBIAN_FRONTEND=noninteractive apt-get install -y adduser 19 | 20 | ENV PLAYBOOK test.yml 21 | RUN ansible-playbook-wrapper -vvv --extra-vars "nginx_use_service=False" 22 | 23 | EXPOSE 27017 24 | 25 | 26 | # 27 | # test phase 28 | # 29 | 30 | RUN echo "===> Patch conf file to allow 0.0.0.0 and disable fork..." && \ 31 | sed -i -e 's/^\(\s*bind_ip\)/#--- \1/' /etc/mongod.conf && \ 32 | sed -i -e 's/^\(\s*fork\)/#--- \1/' /etc/mongod.conf 33 | 34 | 35 | CMD ["mongod", "--config", "/etc/mongod.conf"] 36 | -------------------------------------------------------------------------------- /test/Dockerfile-ubuntu12.04: -------------------------------------------------------------------------------- 1 | # Dockerfile for building image that contains software stack provisioned by Ansible. 2 | # 3 | # Version 1.1 4 | # 5 | 6 | 7 | # pull base image 8 | FROM williamyeh/ansible:ubuntu12.04-onbuild 9 | 10 | MAINTAINER William Yeh 11 | 12 | 13 | # 14 | # build phase 15 | # 16 | 17 | ENV PLAYBOOK test.yml 18 | RUN ansible-playbook-wrapper 19 | 20 | EXPOSE 27017 21 | 22 | 23 | # 24 | # test phase 25 | # 26 | 27 | RUN echo "===> Patch conf file to allow 0.0.0.0 and disable fork..." && \ 28 | sed -i -e 's/^\(\s*bind_ip\)/#--- \1/' /etc/mongod.conf && \ 29 | sed -i -e 's/^\(\s*fork\)/#--- \1/' /etc/mongod.conf 30 | 31 | 32 | CMD ["mongod", "--config", "/etc/mongod.conf"] 33 | -------------------------------------------------------------------------------- /test/Dockerfile-ubuntu14.04: -------------------------------------------------------------------------------- 1 | # Dockerfile for building image that contains software stack provisioned by Ansible. 2 | # 3 | # Version 1.1 4 | # 5 | 6 | 7 | # pull base image 8 | FROM williamyeh/ansible:ubuntu14.04-onbuild 9 | 10 | MAINTAINER William Yeh 11 | 12 | 13 | # 14 | # build phase 15 | # 16 | 17 | ENV PLAYBOOK test.yml 18 | RUN ansible-playbook-wrapper 19 | 20 | EXPOSE 27017 21 | 22 | 23 | # 24 | # test phase 25 | # 26 | 27 | RUN echo "===> Patch conf file to allow 0.0.0.0 and disable fork..." && \ 28 | sed -i -e 's/^\(\s*bind_ip\)/#--- \1/' /etc/mongod.conf && \ 29 | sed -i -e 's/^\(\s*fork\)/#--- \1/' /etc/mongod.conf 30 | 31 | 32 | CMD ["mongod", "--config", "/etc/mongod.conf"] 33 | -------------------------------------------------------------------------------- /test/mongod.conf.j2: -------------------------------------------------------------------------------- 1 | # mongod.conf 2 | # config for MongoDB data server 3 | {% if mongodb_configsvr and '"mongod" in mongodb_components' %} 4 | # (... as a config server) 5 | {% endif %} 6 | 7 | 8 | {% if ansible_os_family == "Debian" %} 9 | 10 | dbpath=/var/lib/mongodb 11 | 12 | {% elif ansible_os_family == "RedHat" %} 13 | 14 | dbpath=/var/lib/mongo 15 | pidfilepath=/var/run/mongodb/mongod.pid 16 | 17 | # fork and run in background 18 | fork=true 19 | 20 | {% endif %} 21 | 22 | 23 | logpath=/var/log/mongodb/mongod.log 24 | logappend=true 25 | #replSet = 26 | 27 | 28 | 29 | 30 | {% if mongodb_configsvr and '"mongod" in mongodb_components' %} 31 | 32 | configsvr = true 33 | port = {{ mongodb_configsvr_port }} 34 | 35 | {% else %} 36 | 37 | #port = 27017 38 | 39 | {% endif %} 40 | 41 | 42 | 43 | 44 | # Listen to local interface only. Comment out to listen on all interfaces. 45 | bind_ip = 127.0.0.1 46 | 47 | #keyFile=/path/to/keyfile 48 | --------------------------------------------------------------------------------