I'm migrating a set of bash scripts that deploy a server to Puppet. Almost all of the functionality has been moved into Puppet, but I can't see how to migrate one bit of the bash script that does the following:

  1. Install PHP.
  2. With a PHP script, generate a random password and store it as a variable in the bash script.
  3. Use that variable elsewhere in the bash script to set the MySQL root password.

How can I set a puppet variable dynamically like this?

btw I'm using Puppet in a standalone version using puppet apply as I don't have a separate server to act as the puppet master. Also, in case anyone is wondering why it's done like this, it's so that the MySQL root password doesn't exist anywhere except on the box where it's used and isn't written to any (readable) files.


You can just use the function "generate" in your manifest to call some kind of random string generator (pwgen?) and assign this value to a variable:


  • Thanks for the suggestion - I'm trying that by doing $test = generate("/usr/bin/php /home/intahwebz/current/tools/genPassword.php") However it gives an error "Generators can only contain alphanumerics, file separators, and dashes at..." Do you know the exact syntax to call it correctly? – Danack May 10 '13 at 15:37
  • Try: generate("/usr/bin/php", "/home/intahwebz/current/tools/genPassword.php") – Pascal Schmiel May 10 '13 at 15:42
  • Thanks, that works. Now just to figure out the ordering. – Danack May 10 '13 at 16:37
  • Ah - it actually look like it can't work. Puppet tries to run the generate command as soon as it can. As it's not a resource there doesn't appear to be a sensible way to get it to wait for another class to be done first. Any ideas? – Danack May 10 '13 at 18:14
  • There are other ways to make something like this work if you had a puppet server, but I believe you can do it it in 2 puppet runs if you're careful with conditionals. – freiheit May 14 '13 at 20:49

It looks like this is not feasible to do with Puppet running in standalone version.

All the variables inside classes are calculated when the scripts are read by Puppet, and so there is no way to make a dependency chain to:

  • Install PHP.
  • Call a PHP script to generate a value.
  • Use the value.

In that order.

Theoretically it may be possible to use [run stages][1] to control this dependency, but these are not usable if your classes are includeed into the project, and so aren't recommended to be used ever.

As I have use a bootstrap script to install Puppet, I may as well just install PHP through the bootstrap script, rather than having Puppet manage it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.