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:
- Install PHP.
- With a PHP script, generate a random password and store it as a variable in the bash script.
- 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:
https://puppet.com/docs/puppet/3.8/function.html#generate
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:
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 areinclude
ed 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.