ansible / ansible.builtin / v2.8.13 / lookup / mongodb lookup info from MongoDB | "added in version" 2.3 of ansible.builtin" Authors: Marcos Diez <marcos (at) unitron.com.br>ansible.builtin.mongodb (v2.8.13) — lookup
pip
Install with pip install ansible==2.8.13
The ``MongoDB`` lookup runs the *find()* command on a given *collection* on a given *MongoDB* server.
The result is a list of jsons, so slightly different from what PyMongo returns. In particular, *timestamps* are converted to epoch integers.
- hosts: all gather_facts: false vars: mongodb_parameters: #mandatory parameters database: 'local' #optional collection: "startup_log" connection_string: "mongodb://localhost/" extra_connection_parameters: { "ssl" : True , "ssl_certfile": /etc/self_signed_certificate.pem" } #optional query parameters, we accept any parameter from the normal mongodb query. filter: { "hostname": "batman" } projection: { "pid": True , "_id" : False , "hostname" : True } skip: 0 limit: 1 sort: [ [ "startTime" , "ASCENDING" ] , [ "age", "DESCENDING" ] ] tasks: - debug: msg="Mongo has already started with the following PID [{{ item.pid }}]" with_mongodb: "{{mongodb_parameters}}"
skip: description: - How many results should be skipped type: integer sort: default: '[]' description: - Sorting rules. Please notice the constats are replaced by strings. type: list limit: description: - How many results should be shown type: integer filter: default: '{}' description: - Criteria of the output type: dict database: description: - Name of the database which the query will be made required: true collection: description: - Name of the collection which the query will be made required: true projection: default: '{}' description: - Fields you want returned type: dict connect_string: default: mongodb://localhost/ description: - Can be any valid MongoDB connection string, supporting authentication, replicasets, etc. - More info at U(https://docs.mongodb.org/manual/reference/connection-string/)