I would like to create a templating system that executes bash within a text file.
For example, let's consider we created a simple template.yaml
file:
my_path: $(echo ${PATH})
my_ip: $(curl -s http://whatismyip.akamai.com/)
some_const: "foo bar"
some_val: $(echo -n $MY_VAR | base64)
The desire is to execute each one, such that the result may look like:
my_path: /Users/roman/foo
my_ip: 1.2.3.4
some_const: "foo bar"
some_val: ABC
How would I go about doing such a substitution?
Reasons for wanting this:
- There are many values, and doing something like a sed or envsubst isn't practical
- It would be common to apply a series of piped transformations
- The configuration file would be populated from numerous sources, all of them essentially bash commands
- I do need to create a yaml file of a specific format (ultimately used by another tool)
- I could create aliases etc to increase readability
- By having it execute in it's own shell none of the semi-sensitive values are stored as in history or as files.
I'm not married to this approach, and would happily attempt a recommendation that fulfils the reasons.