Ansible游戏手册中的MongoDB CRUD操作。

问题描述 投票:0回答:1

谁能分享一个简单的例子,如何在Ansible playbook中使用mongodb模块创建数据库、集合并执行CRUD操作。

mongodb ansible mongodb-query pymongo
1个回答
0
投票

看起来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")
© www.soinside.com 2019 - 2024. All rights reserved.