abs
abs copied to clipboard
a templating function that takes a file and an hash and returns a string (maybe using go template)
from @omissis
This idea stemmed a few weeks ago while I was writing some Packer provisioners using good old shell scripts: I created a few of base images for a bunch of services like mariadb, rabbitmq, strongswan and postgresql.
As you can imagine, I had to manipulate some config files and inject values into them: nothing incredibly fancy, but a bit of nuisance nonetheless: while it's true that bash offers multiline strings and variable interpolations, I imagined building the same thing using Abs and I thought that having the ability to manipulate template files could have improved the structure and readability of my scripts, so that something like this
{ cat >/etc/apt/apt.conf.d/50unattended-upgrades <<EOF
Unattended-Upgrade::Allowed-Origins {
"${distro_id}:${distro_codename}";
"${distro_id}:${distro_codename}-security";
"${distro_id}ESMApps:${distro_codename}-apps-security";
"${distro_id}ESM:${distro_codename}-infra-security";
};
Unattended-Upgrade::Package-Blacklist {
};
Unattended-Upgrade::DevRelease "auto";
Unattended-Upgrade::Mail "[email protected]";
Unattended-Upgrade::MailReport "on-change";
Unattended-Upgrade::Automatic-Reboot "false";
Unattended-Upgrade::Remove-Unused-Kernel-Packages "true";
Unattended-Upgrade::Remove-Unused-Dependencies "true";
EOF
}
could have become something that looks like:
cfg = tpl("/path/to/template", {"distro_codename": "foo", "distro_id": "bar"})
`echo $cfg > /etc/some.thing`