Variable substitution with envsubst
If you need to generate configuration files quickly based on templates, you can use envsubst to help you.
On Fedora, envsubst is part of the gettext package, which is installed by default.
Let’s imagine this template:
- name: $name
group: core
url: "https://$name.wains.be/"
interval: 5m
conditions:
- "[STATUS] == 200"
- "[CERTIFICATE_EXPIRATION] > 48h"
Now export a variable:
export name=blog
Now run envsubst:
$ envsubst < config.yaml
- name: blog
group: core
url: "https://blog.wains.be/"
interval: 5m
conditions:
- "[STATUS] == 200"
- "[CERTIFICATE_EXPIRATION] > 48h"
You can of course redirect the output to a file:
$ envsubst < config.yaml > blog.yaml
$ cat blog.yaml
- name: blog
group: core
url: "https://blog.wains.be/"
interval: 5m
conditions:
- "[STATUS] == 200"
- "[CERTIFICATE_EXPIRATION] > 48h"