Read pillar data from a mongodb collection.
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.
The module shares the same base mongo connection variables as 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 ''.
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 multine dict to work correctly with some experimentation.
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.
Connect to a mongo database and read per-node pillar information.