谁能分享一个简单的例子,如何在Ansible playbook中使用mongodb模块创建数据库、集合并执行CRUD操作。
看起来ansible只提供了普通的管理任务,比如向集群添加Shards或创建用户。
在这种情况下,你必须使用 shell
模块,例如
- copy:
# create or copy .js file with required commands
dest: ~/script-file.js
- shell:
cmd: mongo -u <user> -p <password> ~/script-file.js
对于单个命令,你也可以使用
- shell:
cmd: mongo -u <user> -p <password>
stdin: db.createCollection("col")