community.mongodb.mongodb_shell – Run commands via the MongoDB shell.¶
Note
This plugin is part of the community.mongodb collection (version 1.2.1).
To install it use: ansible-galaxy collection install community.mongodb
.
To use it in a playbook, specify: community.mongodb.mongodb_shell
.
Synopsis¶
Run commands via the MongoDB shell.
Commands provided with the eval parameter or included in a Javascript file.
Attempts to parse returned data into a format that Ansible can use.
Parameters¶
Examples¶
- name: Run the listDatabases command
community.mongodb.mongodb_shell:
login_user: user
login_password: secret
eval: "db.adminCommand('listDatabases')"
- name: List collections and stringify the output
community.mongodb.mongodb_shell:
login_user: user
login_password: secret
eval: "db.adminCommand('listCollections')"
stringify: yes
- name: Run the showBuiltinRoles command
community.mongodb.mongodb_shell:
login_user: user
login_password: secret
eval: "db.getRoles({showBuiltinRoles: true})"
- name: Run a js file containing MongoDB commands with pseudo-idempotency
community.mongodb.mongodb_shell:
login_user: user
login_password: secret
file: "/path/to/mongo/file.js"
idempotent: yes
- name: Provide a couple of additional cmd args
community.mongodb.mongodb_shell:
login_user: user
login_password: secret
eval: "db.adminCommand('listDatabases')"
additional_args:
verbose: True
networkMessageCompressors: "snappy"
Return Values¶
Common return values are documented here, the following are the fields unique to this module:
Authors¶
Rhys Campbell (@rhysmeister)