Reputation: 3307
I'm working on extending the puppetlabs-mongodb module to allow for user authentication. The challenge is that mongo changed its mechanism for enabling user authentication between version 2.2 and version 2.4 and so distinct code must be run in order to give a user authentication credentials to a database.
My initial thought was to create a custom facter fact that basically captured the output of mongod --version
, but it appears that facter facts are loaded before the puppet manifest is executed. Is there a way to execute arbitrary code at run time during puppet execution so that I can access mongod --version
and decide which method to use to enable user authentication?
Note: One approach would be to have puppet run a single script to create user credentials and have the script detect the
mongod --version
at runtime. This doesn't seem like a very puppet-y way of doing things, but perhaps I am off base on that. What is the best way to handle the need for accessing variables dynamically in puppet/facter?
Upvotes: 2
Views: 2129
Reputation: 11
Just put your Ruby code in a ERB template and use template("${module_name}/templ.erb")
to return your version string.
Upvotes: 1
Reputation: 3307
The word from @puppetlabs is that you can not run ruby code (or any other code) dynamically during a puppet run. The "right" way to do this is in the note above with an exec
statement that dynamically checks for the mongodb version. For details on the implementation, see manifests/add_user.pp and the associated templates/add_user*.erb.
If anyone has a more "puppety" method for accomplishing this, I'd love to learn about it!
Upvotes: 2