Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

a templating function that takes a file and an hash and returns a string (maybe using go template) #436

Open
odino opened this issue Jun 2, 2021 · 1 comment
Milestone

Comments

@odino
Copy link
Collaborator

odino commented Jun 2, 2021

from @omissis

@odino odino added this to the cauldron milestone Jun 2, 2021
@omissis
Copy link

omissis commented Jun 7, 2021

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 "info@example.com";
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`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants