Module Expr Str ImportFrom alias Import alias Import alias TryExcept body Import alias Assign NameStore NameLoad handlers ExceptHandler type NameLoad body Assign NameStore NameLoad Assign NameStore Dict Str Str Str Str Str Str Str Str Num Str FunctionDef arguments args defaults body If UnaryOpNot NameLoad body Return NameLoad Return Str decorator_list Assign NameStore Call AttributeLoad NameLoad attr NameLoad FunctionDef arguments args NameParam NameParam NameParam NameParam NameParam NameParam NameParam defaults Str Str NameLoad Str NameLoad body Expr Str Assign NameStore SubscriptLoad NameLoad Index Str Assign NameStore SubscriptLoad NameLoad Index Str Expr Call AttributeLoad NameLoad attr Call AttributeLoad Str attr NameLoad NameLoad Assign NameStore Call AttributeLoad NameLoad attr NameLoad NameLoad Expr Call AttributeLoad NameLoad attr Call AttributeLoad Str attr SubscriptLoad NameLoad Index Str Assign NameStore SubscriptLoad NameLoad Index SubscriptLoad NameLoad Index Str Assign NameStore Call AttributeLoad NameLoad attr Str Assign NameStore Call AttributeLoad NameLoad attr Str If BoolOpAnd NameLoad NameLoad body Expr Call AttributeLoad NameLoad attr Call AttributeLoad Str attr NameLoad Expr Call AttributeLoad NameLoad attr NameLoad NameLoad If NameLoad body Assign NameStore Call AttributeLoad NameLoad attr NameLoad NameLoad NameLoad Expr Call AttributeLoad NameLoad attr Call AttributeLoad Str attr NameLoad NameLoad Assign NameStore Call AttributeLoad SubscriptLoad NameLoad Index NameLoad attr Dict NameLoad NameLoad keyword NameLoad If NameLoad body If NameLoad body Expr Call AttributeLoad NameLoad attr Call AttributeLoad Str attr NameLoad orelse Expr Call AttributeLoad NameLoad attr Str If CompareIn Str NameLoad body Assign SubscriptStore NameLoad Index Str Call NameLoad SubscriptLoad NameLoad Index Str Return NameLoad orelse Expr Call AttributeLoad NameLoad attr Call AttributeLoad Str attr NameLoad Return Dict decorator_list
N/A N/A 
Read Pillar data from a mongodb collection

:depends: pymongo (for salt-master)

This module will load a node-specific pillar dictionary from a mongo
collection. It uses the node's id for lookups and can load either the whole
document, or just a specific field from that
document as the pillar dictionary.

Salt Master Mongo Configuration
===============================

The module shares the same base mongo connection variables as
:py:mod:`salt.returners.mongo_return`. These variables go in your master
config file.

   * ``mongo.db`` - The mongo database to connect to. Defaults to ``'salt'``.
   * ``mongo.host`` - The mongo host to connect to. Supports replica sets by
     specifying all hosts in the set, comma-delimited. Defaults to ``'salt'``.
   * ``mongo.port`` - The port that the mongo database is running on. Defaults
     to ``27017``.
   * ``mongo.user`` - The username for connecting to mongo. Only required if
     you are using mongo authentication. Defaults to ``''``.
   * ``mongo.password`` - The password for connecting to mongo. Only required
     if you are using mongo authentication. Defaults to ``''``.


Configuring the Mongo ext_pillar
================================

The Mongo ext_pillar takes advantage of the fact that the Salt Master
configuration file is yaml. It uses a sub-dictionary of values to adjust
specific features of the pillar. This is the explicit single-line dictionary
notation for yaml. One may be able to get the easier-to-read multi-line dict to
work correctly with some experimentation.

.. code-block:: yaml

  ext_pillar:
    - mongo: {collection: vm, id_field: name, re_pattern: \.example\.com, fields: [customer_id, software, apache_vhosts]}

In the example above, we've decided to use the ``vm`` collection in the
database to store the data. Minion ids are stored in the ``name`` field on
documents in that collection. And, since minion ids are FQDNs in most cases,
we'll need to trim the domain name in order to find the minion by hostname in
the collection. When we find a minion, return only the ``customer_id``,
``software``, and ``apache_vhosts`` fields, as that will contain the data we
want for a given node. They will be available directly inside the ``pillar``
dict in your SLS templates.


Module Documentation
====================
 __future__ absolute_import N/A logging N/A re N/A N/A N/A pymongo N/A HAS_PYMONGO True N/A N/A N/A ImportError N/A N/A HAS_PYMONGO False N/A __opts__ N/A mongo.db mongo.host mongo.password mongo.port mongo.user salt salt 27017 __virtual__ N/A N/A N/A N/A N/A N/A HAS_PYMONGO N/A N/A False N/A mongo N/A N/A log N/A N/A logging getLogger __name__ ext_pillar N/A N/A minion_id pillar collection id_field re_pattern re_replace fields N/A pillar _id None None N/A N/A 
    Connect to a mongo database and read per-node pillar information.

    Parameters:
        * `collection`: The mongodb collection to read data from. Defaults to
          ``'pillar'``.
        * `id_field`: The field in the collection that represents an individual
          minion id. Defaults to ``'_id'``.
        * `re_pattern`: If your naming convention in the collection is shorter
          than the minion id, you can use this to trim the name.
          `re_pattern` will be used to match the name, and `re_replace` will
          be used to replace it. Backrefs are supported as they are in the
          Python standard library. If ``None``, no mangling of the name will
          be performed - the collection will be searched with the entire
          minion id. Defaults to ``None``.
        * `re_replace`: Use as the replacement value in node ids matched with
          `re_pattern`. Defaults to ''. Feel free to use backreferences here.
        * `fields`: The specific fields in the document to use for the pillar
          data. If ``None``, will use the entire document. If using the
          entire document, the ``_id`` field will be converted to string. Be
          careful with other fields in the document as they must be string
          serializable. Defaults to ``None``.
     N/A host N/A __opts__ N/A mongo.host N/A port N/A __opts__ N/A mongo.port N/A N/A N/A log info N/A N/A connecting to {0}:{1} for mongo ext_pillar format host port N/A conn N/A N/A pymongo MongoClient host port N/A N/A N/A log debug N/A N/A using database '{0}' format N/A __opts__ N/A mongo.db N/A mdb N/A conn N/A N/A __opts__ N/A mongo.db N/A user N/A N/A __opts__ get mongo.user N/A password N/A N/A __opts__ get mongo.password N/A N/A user password N/A N/A N/A N/A log debug N/A N/A authenticating as '{0}' format user N/A N/A N/A mdb authenticate user password N/A re_pattern N/A N/A minion_id N/A N/A re sub re_pattern re_replace minion_id N/A N/A N/A log info N/A N/A ext_pillar.mongo: looking up pillar def for {{'{0}': '{1}'}} in mongo format id_field minion_id N/A result N/A N/A N/A mdb N/A collection find_one N/A id_field minion_id projection fields N/A result N/A N/A fields N/A N/A N/A N/A log debug N/A N/A ext_pillar.mongo: found document, returning fields '{0}' format fields N/A N/A N/A N/A log debug ext_pillar.mongo: found document, returning whole doc N/A N/A _id result N/A N/A N/A result N/A _id N/A str N/A result N/A _id N/A result N/A N/A N/A N/A log debug N/A N/A ext_pillar.mongo: no document found in collection {0} format collection N/A N/A N/A