ansible 安装 docker + mongodb

1、编辑配置文件

先写一点,方便后期修改配置

vim /root/mongod.conf

storage:
  dbPath: /data/db

2、编辑docker-mongodb.yml

---
- hosts: 192.168.59.103
  remote_user: root

  tasks:
    - name: start docker.service
      command: systemctl start docker
    - name: mkdir dir
      file: name=/data/mongo/{conf,db} state=directory
    - name: coyp conf
      copy: src=/root/mongod.conf dest=/data/mongo/conf
    - name: run mongo
      shell: docker run -d --name mongo -p 27017:27017 -e MONGO_INITDB_ROOT_USERNAME=admin -e MONGO_INITDB_ROOT_PASSWORD=123456 -v /data/mongo/db:/data/db -v /data/mongo/conf:/data/mongo/conf mongo --config /data/mongo/conf/mongod.conf --auth

3、验证

  ansible-playbook docker-mongodb.yml 

 

posted @ 2022-09-27 10:42  leihongnu  阅读(56)  评论(0编辑  收藏  举报