Mongodb

使用 ansible playbook 創建 mongodb 數據庫

  • July 13, 2021

如何使用 Ansible 創建 MongoDB 數據庫?可能嗎?

如果沒有,我可以用 bash 腳本做到這一點嗎?

我嘗試將 mongodb_user 模組用於 Ansible,但如果沒有現有表,它就無法工作。

- name: Create MongoDB root user siteRootAdmin
 mongodb_user:
   login_port: "27017"
   database: "admin"
   name: "{{ mongodb_admin_user }}"
   password: "{{ mongodb_admin_password }}"
   roles: "root"

- name: Create MongoDB administrative user siteUserAdmin
 mongodb_user:
   login_user: "{{ mongodb_admin_user }}"
   login_password: "{{ mongodb_admin_password }}"
   login_port: "27017"
   database: "e-gov"
   name: "{{ mongodb_user }}"
   password: "{{ mongodb_password }}"
   roles:
     - { db: "admin", role: "readWrite" }
     - { db: "{{ mongodb_database }}", role: "readWrite" }

- name: Create MongoDB backup user siteUserBackup
 mongodb_user:
   login_user: "{{ mongodb_admin_user }}"
   login_password: "{{ mongodb_admin_password }}"
   login_port: "27017"
   database: "e-gov"
   name: "{{ mongodb_backup_user }}"
   password: "{{ mongodb_backup_password }}"
   roles:
     - { db: "admin", role: "backup" }

我這樣做了,它適用於 ansible 2.2.0^

引用自:https://dba.stackexchange.com/questions/185240