playbook 文件
- [root@localhost ~]# cat deploy_mongo.YAML
- ---
- - hosts: webservers
- become: yes
- become_method: sudo
- vars:
- mongodb_datadir_prefix: /data
- mongod_port: 25000
- tasks:
- - name: create the MongoDB user
- user: name=MongoDB comment="MongoDB"
- - name: create the data directory for metadata
- file: path={{ mongodb_datadir_prefix }} owner=MongoDB group=MongoDB state=directory
- - name: install the MongoDB
- command: yum install MongoDB-org -y
- - name: create data directory for MongoDB
- file:
- path: "{{ mongodb_datadir_prefix }}/mongo-{{ ansible_hostname }}"
- owner: MongoDB
- group: MongoDB
- state: directory
- - name: create log directory for MongoDB
- file: path=/var/log/MongoDB owner=MongoDB group=MongoDB state=directory
- - name: create the MongoDB configuration file
- template: src=/root/MongoDB.conf.j2 dest=/etc/mongod.conf
- - name: start MongoDB
- command: systemctl start mongod.service
模板文件:
注意模板里面最多渲染个端口, 渲染太多 MongoDB 总是无法启动
- [root@localhost ~]# cat MongoDB.conf.j2
- # mongod.conf
- # for documentation of all options, see:
- # http://docs.mongodb.org/manual/reference/configuration-options/
- # where to write logging data.
- systemLog:
- destination: file
- logAppend: true
- path: /var/log/MongoDB/mongod.log
- # Where and how to store data.
- storage:
- dbPath: /var/lib/mongo
- journal:
- enabled: true
- # engine:
- # mmapv1:
- # wiredTiger:
- # how the process runs
- processManagement:
- fork: true # fork and run in background
- pidFilePath: /var/run/MongoDB/mongod.pid # location of pidfile
- # network interfaces
- net:
- port: {{ mongod_port }}
- bindIp: 127.0.0.1 # Listen to local interface only, comment to listen on all interfaces.
- #security:
- #operationProfiling:
- #replication:
- #sharding:
- ## Enterprise-Only Options
- #auditLog:
- #snmp:
来源: http://www.bubuko.com/infodetail-2923969.html