File manager - Edit - /opt/saltstack/salt/lib/python3.10/site-packages/salt/pillar/__pycache__/mongo.cpython-310.pyc
Back
o ;j7 � @ sn d Z ddlZddlZddlZzddlZdZW n ey! dZY nw dd� Ze� e �Z dd d�ZdS ) 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_future_return`. These variables go in your master config file. .. code-block:: yaml mongo.db: <database name> mongo.host: <server ip address> mongo.user: <MongoDB username> mongo.password: <MongoDB user password> mongo.port: 27017 Or single URI: .. code-block:: yaml mongo.uri: URI where uri is in the format: .. code-block:: text mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]] Example: .. code-block:: text mongodb://db1.example.net:27017/mydatabase mongodb://db1.example.net:27017,db2.example.net:2500/?replicaSet=test mongodb://db1.example.net:27017,db2.example.net:2500/?replicaSet=test&connectTimeoutMS=300000 More information on URI format can be found in https://docs.mongodb.com/manual/reference/connection-string/ 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 ==================== � NTFc C s t sdS dS )NFZmongo)�HAS_PYMONGO� r r �E/opt/saltstack/salt/lib/python3.10/site-packages/salt/pillar/mongo.py�__virtual__Z s r �pillar�_id� c C s6 t �d�}t �d�}t �d�} t �d�} t �d�}t �d�}|r@|r*|r*tj�d��tj�|� t�|�} t � d|� | �� }nt � d || � tj|| | |d �} t �d|� | | }|rct �||| �} t � d|| � || j|| i|d �}|r�|r�t �d|� nt �d� d|v r�t|d �|d<