W3cubDocs

/Ansible 2.9

mongodb – lookup info from MongoDB

Synopsis

  • 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.

Requirements

The below requirements are needed on the local master node that executes this lookup.

  • pymongo >= 2.4 (python library)

Parameters

Parameter Choices/Defaults Configuration Comments
collection
- / required
Name of the collection which the query will be made
connect_string
-
Default:
"mongodb://localhost/"
Can be any valid MongoDB connection string, supporting authentication, replicasets, etc.
database
- / required
Name of the database which the query will be made
filter
dictionary
Default:
"{}"
Criteria of the output
limit
integer
How many results should be shown
projection
dictionary
Default:
"{}"
Fields you want returned
skip
integer
How many results should be skipped
sort
list
Default:
"[]"
Sorting rules. Please notice the constats are replaced by strings.

Notes

Examples

- 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}}"

Status

Authors

  • Marcos Diez <marcos (at) unitron.com.br>

Hint

If you notice any issues in this documentation, you can edit this document to improve it.

Hint

Configuration entries for each entry type have a low to high priority order. For example, a variable that is lower in the list will override a variable that is higher up.

© 2012–2018 Michael DeHaan
© 2018–2019 Red Hat, Inc.
Licensed under the GNU General Public License version 3.
https://docs.ansible.com/ansible/2.9/plugins/lookup/mongodb.html