Puppet generating variables inside script

puppet

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.

Best Answer

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:

https://puppet.com/docs/puppet/3.8/function.html#generate