利用ansible部署mongodb,ansible部署mongodb


利用ansible部署mongodb


---
- hosts: db_server
  become: yes
  become_method: sudo 

  vars:
    mengodb_datadir_prefix: /data 
    mongod_port: 27018

  tasks:
    - name: Create the mongodb user
      user: name=mongodb comment="MongoDB"

    - name: Create the data directory for the namenode metadata
      file: path={{mengodb_datadir_prefix}} owner=mongodb group=mongodb state=directory

    - name: Install the MongoDB package
      yum: name={{ item }} state=installed
      with_items:
        - mongodb-server
        - mongodb-clients
        - rsyslog-mongodb

    - name: create data directory for mongodb
      file:
        path: "{{ mengodb_datadir_prefix }}/mongo-{{ ansible_hostname }}"
        state: directory
        owner: mongodb
        group: mongodb

    - name: create log directory for mongodb
      file: path=/var/log/mongo state=directory owner=mongodb group=mongodb

    - name: create the mongodb startup file
      template: src=mongod.j2 dest=/etc/init.d/mongod-{{ ansible_hostname}} mode=0655

    - name: create the mongodb configuration file
      template: src=mongod.conf.j2 dest=/etc/mongod-{{ ansible_hostname }}.conf 

    - name: copy the keyfile for authentication
      copy: src=secret dest={{ mengodb_datadir_prefix }}/secret owner=mongodb group=mongodb mode=0400

    - name: start the mongodb service
      command: create=/var/lock/subsys/mongod-{{ ansible_hostname}}  /etc/init.d/mongodb-{{ ansible_hostname }} start

相关内容

    暂无相关文章