Ansible安装MongoDB

  • Post author:
  • Post category:Ansible
  • Page Views 1070 阅读

1.deploy_mongodb.yml

---
- hosts: dbservers
  become: yes
  become_method: yes
  vars:
    mongodb_datadir_prefix: /data
    mongodb_port: 27018
    
  task:
    - name: create the mongodb user
      user: name=mongodb comment="Mongodb"
      
    - name: create data dir for the namenode metadata
      file: path={{ mongodb_datadir_prefix }} owner=mongodb group=mongodb state=directory
      
    - name: install mongodb
      yum: name={{ item }} state=installed
      with_item:
        - mongodb-server
        - mongodb-clients
        - rsyslog-mongodb
        
    - name: create data dir for mongodb
      file:
        path: "{{ mongodb_datadir_prefix }}/mongodb-{{ ansible_hostname }}"
        state: directory
        owner: mongodb
        group: mongodb
        
    - name: create log dir for mongodb
      file: path=/var/log/mongodb state=directory owner=mongodb group=group
      
    - name: create mongodb startup file
      template: src=mongodb.j2 dest=/etc/init.d/mongodb-{{ ansible_hostname }} mode=0655
      
    - name: create config file
      template: src=mongodb.conf.j2 dest=/etc/mongodb-{{ ansible_hostname }}.conf
      
    - name: copy keyfile for authentication
      copy: src=secret dest={{ mongodb_datadir_prefix }}/secret owner=mongodb group=mongodb mode=0400
      
    - name: start mongodb service
      command: creates=/var/lock/subsys/mongodb-{{ ansible_hostname }} /etc/init.d/mongodb-{{ ansible_hostname }} start


「 文章如果对你有帮助,请点个赞哦^^ 」 

0