Skip to main content

Posts

Featured

Quick templating with python in a shell heredoc

Say you access various data sources (primarily enviroment vars) that is to be mixed into a result output textfile. What is the quickest and most powerful way? Replacing variable refs inside a pure text file has many solutions out there. Most ones come as compiled, extra install or limited in scope. ( m4 , envsubst , gomplate ) Here I will examine solving this using the python3 interpreter directly from a single shell command. No pip dependencies, no script file. In most cases templating ends up being executed in a CI/CD docker container where you would like to avoid complex dependencies. Python3 might not be an "extra install" if you work with deployments to AWS and use either aws-cli or botocore directly. 💬 Why a heredoc and not a .py scriptfile? In my case a limited "reuse" system ( gitlab include ) require passing the shell commands inside yaml and no extra files allowed, and shell heredoc is quite elegant and makes you focus on compact code. Solution with

Latest posts