A flexible commandline tool for template rendering. Supports lots of local and remote datasources.

Overview

gomplate logo

Read the docs at docs.gomplate.ca, chat with developers and community in the #gomplate channel on Gophers Slack

Build Status Build Go Report Card Codebeat Status Coverage Total Downloads CII Best Practices

hairyhenderson/gomplate on DockerHub DockerHub Stars DockerHub Pulls DockerHub Image Layers DockerHub Latest Version DockerHub Latest Commit

Chocolatey Chocolatey

Install Docs Slack Discussions

gomplate is a template renderer which supports a growing list of datasources, such as: JSON (including EJSON - encrypted JSON), YAML, AWS EC2 metadata, BoltDB, Hashicorp Consul and Hashicorp Vault secrets.

Come chat with developers and community in the #gomplate channel on Gophers Slack and on GitHub Discussions!

Here are some hands-on examples of how gomplate works:

$ # at its most basic, gomplate can be used with environment variables...
$ echo 'Hello, {{ .Env.USER }}' | gomplate
Hello, hairyhenderson

$ # but that's kind of boring. gomplate has tons of functions to do useful stuff, too
$ gomplate -i 'the answer is: {{ mul 6 7 }}'
the answer is: 42

$ # and, since gomplate uses Go's templating syntax, you can do fun things like:
$ gomplate -i '{{ range seq 5 1 }}{{ . }} {{ if eq . 1 }}{{ "blastoff" | toUpper }}{{ end }}{{ end }}'
5 4 3 2 1 BLASTOFF

$ # the real fun comes when you use datasources!
$ cat ./config.yaml
foo:
  bar:
    baz: qux
$ gomplate -d config=./config.yaml -i 'the value we want is: {{ (datasource "config").foo.bar.baz }}'
the value we want is: qux

$ # datasources are defined by URLs, and gomplate is not limited to just file-based datasources:
$ gomplate -d ip=https://ipinfo.io -i 'country code: {{ (ds "ip").country }}'
country code: CA

$ # standard input can be used as a datasource too:
$ echo '{"cities":["London", "Johannesburg", "Windhoek"]}' | gomplate -d city=stdin:///in.json -i '{{ range (ds "city").cities }}{{.}}, {{end}}'
London, Johannesburg, Windhoek, 

$ # and here's something a little more complicated:
$ export CITIES='city: [London, Johannesburg, Windhoek]'
$ cat in.tmpl
{{ range $i, $city := (ds "cities").city -}}
{{ add 1 $i }}: {{ include "weather" (print $city "?0") }}
{{ end }}
$ gomplate -d 'cities=env:///CITIES?type=application/yaml' -d 'weather=https://wttr.in/?0' -H 'weather=User-Agent: curl' -f in.tmpl
1: Weather report: London

    \  /       Partly cloudy
  _ /"".-.     4-7 °C
    \_(   ).   ↑ 20 km/h
    /(___(__)  10 km
               0.0 mm

2: Weather report: Johannesburg

    \  /       Partly cloudy
  _ /"".-.     15 °C
    \_(   ).   ↘ 0 km/h
    /(___(__)  10 km
               2.2 mm

3: Weather report: Windhoek

    \  /       Partly cloudy
  _ /"".-.     20 °C
    \_(   ).   ↑ 6 km/h
    /(___(__)  20 km
               0.0 mm

Read the documentation at docs.gomplate.ca, and join the discussion in GitHub Discussions!

Please report any bugs found in the issue tracker.

License

The MIT License

Copyright (c) 2016-2021 Dave Henderson

Analytics

Comments
  • nested template technique?

    nested template technique?

    Is there a way to do this? file data:

    ---
    a: 1
    

    template1 data:

    Welcome to {{.a}
    {{ if .a == 1}} 
    {{ template "foo" }}
    {{ end - }}
    

    It seems like --input-dir just renders everything unconditionally.
    It seems like -d foo=template://foo.t could be used treat conditional (nested) templates as datasources. Since go templates need names, it fits with the -d scheme.

    I ran into trouble with -d and the use of a .t suffix trying to sniff mime typing so maybe a different switch with nearly identical behavior as -d that can be used for defineing templates for use in {{template "foo"}}...

    Is there another way to do it?

    Thanks for doing gomplate!

    opened by f4tq 24
  • Is it possible to generate multiple output files from one template?

    Is it possible to generate multiple output files from one template?

    I have a datasource (a Yaml file) with a bunch of services listed. For each service, I need to create a Dockerfile - all will be built with the same template - which some things varying by the service name.

    So I have one template - and want to create N files with that template based on the data.

    How can I do that with Gomplate? I feel like it should be possible but am struggling to think how.

    enhancement new function 
    opened by rayjlinden 18
  • Add --input-dir and --output-dir as options

    Add --input-dir and --output-dir as options

    • Use these options when a whole directory hierarchy needs to be processed.
    • Extracted file processing logic in an extra process.go

    Partial solution to #117

    Bear with me, Golang is not my mother tongue (which was in fact Perl at those days, but is Java & JavaScript since some times). Looking forward to a review ;-)

    enhancement 
    opened by rhuss 16
  • Support for `required`

    Support for `required`

    what

    A required function that allows you to declare a particular values entry as required for template rendering. If the value is empty, the template rendering will fail with a user submitted error message.

    This function is available in helm.

    why

    • Sometimes we need to ensure user has defined specific environment variables or the rendered template is invalid.
    • Outputting helpful messages will make this easier

    example

    {{- required "A valid API_KEY entry required!" .Env.API_KEY -}}
    

    references:

    • https://github.com/kubernetes/helm/blob/master/docs/charts_tips_and_tricks.md#know-your-template-functions
    new function 
    opened by osterman 14
  • add k8s configmap as source

    add k8s configmap as source

    Solves #116. Currently it lacks integration tests. I would like to know which kind of integration test you may prefer:

    1. Using minikube (https://github.com/kubernetes/minikube). Basically it will spin up a virtualmaching with an all-in-one node Kubernetes cluster (this is how I have developed this new data source)
    2. Graping a valid Kubernetes API answer to emulate it (as with awssvc)

    The good point about 1 is that it will also help with any other k8s datasource (Secrets for example), but it is more complex and heavy.

    enhancement 
    opened by josledp 14
  • Update k8s.io/client-go to a valid version

    Update k8s.io/client-go to a valid version

    The current import of k8s.io/client-go v11.0.0+incompatible causes any project inheriting from this to loose their correct k8s.io/client-go import. Could you pick a version from K8s v1.17 upwards (v0.x.y) and use that library version (e.g. k8s.io/client-go v0.18.15 for K8s v1.18).

    If you have a dependency forcing you to k8s.io/client-go v11.0.0+incompatible please could you use the following pattern to fix projects consuming this project.

    // Pin kubernetes dependencies to 1.18.15
    replace (
    	k8s.io/api => k8s.io/api v0.18.15
    	k8s.io/apimachinery => k8s.io/apimachinery v0.18.15
    	k8s.io/client-go => k8s.io/client-go v0.18.15
    )
    
    require (
    	k8s.io/client-go v11.0.0+incompatible
    )
    
    cleanup dependencies 
    opened by stevehipwell 12
  • YAML Files with KQL Code

    YAML Files with KQL Code

    Hi,

    Apologies for the bold text, it doesn't allow me to revert to normal text...

    Please let me know if the following is possible with gomplate.

    I have a main template called alert001.yaml with the following KQL Query:


    //MasterTemplate

    query: | AzureActivity | where TimeGenerated between (startofday(ago(starttime)) .. startofday(ago(endtime))) | where OperationName in~ (szOperationNames) | summarize StartTimeUtc = min(TimeGenerated), EndTimeUtc = max(TimeGenerated), ActivityTimeStamp = makelist(TimeGenerated), ActivityStatus = makelist(ActivityStatus),


    Based on the above template, I need to create customer yaml files, example alert001-customer001.yaml. On the customer YAML file I need to add few additional lines of code on the KQL and this line of code has to be on the specific line it cannot be and the end of the code, etc.

    //Customer YAML Files

    AzureActivity | where callerIPAddress != "192.168.1.1" | where TimeGenerated between (startofday(ago(starttime)) .. startofday(ago(endtime))) | where OperationName in~ (szOperationNames) | summarize StartTimeUtc = min(TimeGenerated), EndTimeUtc = max(TimeGenerated), ActivityTimeStamp = makelist(TimeGenerated), ActivityStatus = makelist(ActivityStatus)

    Whenever we update the main template we will like it to reflect on the alert001-customer001.yaml, alert001-customer002.yaml, alert001-customer003.yaml files. In other words to append these files..

    Any changes on the customer files will a trigger a CI/CD deployment to the Azure Sentinel environments...

    Is that possible via gomplate? To have a main YAML template that will cascade any changes to the customer YAML files?

    opened by kay07949 10
  • Default values for variables

    Default values for variables

    Is there a way to use a default value when a variable isn't defined?

    Something like: {{(ds "config").notes | default "this a default note")}}

    question 
    opened by vascop 10
  • Vault write support

    Vault write support

    This requires #177 to be merged first.

    This PR adds write support to the Vault datasource, enabling use of dynamic secrets (such as database credentials).

    enhancement 
    opened by stuart-c 10
  • Add `go-sockaddr` functions

    Add `go-sockaddr` functions

    This is an issues to discuss the acceptability and design for a large feature which I think would be useful in gomplate - the ability to execute go-sockaddr pipelines.

    The go-sockaddr library was written primarily by @sean- for use in HashiCorp runtime tools to allow for evaluation of network interfaces against heuristics to avoid hard-coding interface names, IP addresses and so forth during configuration. Consul and Nomad (and I believe soon Vault) all support the templates in configuration fields such as bind.

    Templates take the form of a Go function pipeline, and provide functionality such as finding an IP address that:

    • is attached to a default route (GetDefaultInterfaces())
    • is contained within a CIDR block (IfByNetwork())
    • is an RFC1918 address (IfByRFC("1918"))
    • is ordered (OrderedIfAddrBy(args) where args includes AscIfType, AscNetworkSize)
    • excludes all IPv6 addresses (IfByType("^(IPv4)$"))
    • is larger than a /32 (IfByMaskSize(32))
    • is not on a down interface (ExcludeIfs("flags", "down"))
    • preferences an IPv6 address over an IPv4 address (SortIfByType() + ReverseIfAddrs()); and
    • excludes any IP in RFC6890 address (IfByRFC("6890"))

    I believe this would be a fairly straightforward lift-and-shift to support all of the functions supported by go-sockaddr in gomplate, and it would make rendering templates with networking aspects more flexible. Two possible approaches seem to exist:

    1. Add the go-sockaddr-supplied functions to gomplate directly
    2. Add a function named something like sockaddr which takes a template to render as a parameter.

    I'm happy to take a look at doing this work, but want to confirm that the feature set is of interest prior to doing so.

    enhancement 
    opened by jen20 10
  • Support Kubernetes ConfigMaps as datasources

    Support Kubernetes ConfigMaps as datasources

    It would be awesome if Kubernetes ConfigMaps could be used as datasources. This would be a perfect fit when gomplate is used as an init-container which can be used to prepare configuration files for an application (like a standalone.xml for Wildfly app server).

    Currently this can be done via ConfigMap backed volumes but a direct K8s support would be nicer, of course as it reduces the configuration overhead within Kubernetes.

    enhancement 
    opened by rhuss 10
  • New coll.Index function

    New coll.Index function

    Adds an alternative to the index built-in which supports pipeline use, and is more strict (errors when map key is not found, rather than returning zero value).

    Related to #1545

    Signed-off-by: Dave Henderson [email protected]

    documentation api/minor new function 
    opened by hairyhenderson 0
  • Clarify documentation to highlight the differences between 'index' and '.'

    Clarify documentation to highlight the differences between 'index' and '.'

    Related to https://github.com/hairyhenderson/gomplate/discussions/1545

    Clarifies the docs, as mentioned here: https://github.com/hairyhenderson/gomplate/discussions/1545#discussioncomment-4007859

    Signed-off-by: Dave Henderson [email protected]

    documentation 
    opened by hairyhenderson 0
  • Use one decoder for data.JSON, data.YAML. Deprecate data.JSONArray and data.YAMLArray

    Use one decoder for data.JSON, data.YAML. Deprecate data.JSONArray and data.YAMLArray

    At first, thank you for very useful product. I found it during searching for golang templating tool for DevOps needs after I started prototyping own tool with similar functionality, but now I decided to use gomplate and want to contribute.

    During exploring and using gomplate, I faced with separation on converting on JSON and YAML data. This separation was confused me, because from my point of view there's no need to have it. So I decided to contribute some chages to make user experience smoother.

    What actually changed in this PR:

    • data.JSON and data.YAML is uses one unmarshaler (i.e. it now actually aliases) because valid JSON is valid YAML;
    • both data.JSON and data.YAML supports convertion of any valid data types for this formats, including arrays;
    • data.JSONArray and data.YAMLArray is deprecated, because this functionality can be achieved by using data.JSON and data.YAML, so it also only aliases, to keep compatibility;
    • EJSON support is still here, but I added additinal stringifyMapKeys in output processing;

    IMHO this changes will simplify usage of gomplate, because there's no need to decide which of YAML* or JSON* method use.

    documentation 
    opened by RaveNoX 1
  • Accept arguments for command in plugin definition

    Accept arguments for command in plugin definition

    Currently plugin definitions only accept an executable, so there is no way to pass some pre-defined arguments to precede the ones from the template invocation.

    As a (somewhat contrived) example, If i want a plugin to evaluate a python expression, I should be able to do:

    plugins:
      py: ["python3", "-c"]
    
    {{ py "print('Hello, world')" }}
    

    So that I don't need to have "-c" in every invocation.

    enhancement 
    opened by danielkza 2
  • Release bump for golang 1.19.2 new public cves

    Release bump for golang 1.19.2 new public cves

    Looking at the following which may be applicable:

    • https://nvd.nist.gov/vuln/detail/CVE-2022-41715
    • https://nvd.nist.gov/vuln/detail/CVE-2022-2879

    Thanks!

    security 
    opened by twk3 1
  • Problem with path in checksums file

    Problem with path in checksums file

    Trying to install the latest binary release from Ansible while checking the checksum using Ansible's get_url method, I've encountered the problem that the binary path in the sha256 checksums file is prefixed with binary/ which is not the case in the URL, so Ansible can't find the file and verify the checksum.

    Is this expected behavior or a real problem ?

    Example Ansible task :

    - name: download and install gomplate
      get_url:
        url: "https://github.com/hairyhenderson/gomplate/releases/download/v3.11.3/gomplate_linux-amd64"
        checksum: "sha256:https://github.com/hairyhenderson/gomplate/releases/download/v3.11.3/checksums-v3.11.3_sha256.txt"
        dest: "/usr/local/bin/gomplate"
        backup: true
        owner: root
        group: root
        mode: 0755
      tags: gomplate
    

    Extract from https://github.com/hairyhenderson/gomplate/releases/download/v3.11.3/checksums-v3.11.3_sha256.txt :

    ...
    2c67ef580d2416e82dc2ab8f0c30e1bf372dcd3e8511073df9310d91dc3d5f94  bin/gomplate_linux-amd64
    ...
    

    Output of ansible --version :

    ansible 2.9.27
      ...
      ansible python module location = /usr/lib/python3.6/site-packages/ansible
      executable location = /usr/bin/ansible
      python version = 3.6.8 (default, Jan 14 2022, 11:04:20) [GCC 8.5.0 20210514 (Red Hat 8.5.0-7)]
    

    When running the Ansible task the obtained error message is :

    fatal: [myserver.example.com]: FAILED! => {"changed": false, "msg": "Unable to find a checksum for file 'gomplate_linux-amd64' in 'https://github.com/hairyhenderson/gomplate/releases/download/v3.11.3/checksums-v3.11.3_sha256.txt'"}
    
    opened by tamere-allo-peter 8
Releases(v3.11.3)
Owner
Dave Henderson
Just some guy...
Dave Henderson
Robust, flexible and resource-efficient pipelines using Go and the commandline

Robust, flexible and resource-efficient pipelines using Go and the commandline Project links: Documentation & Main Website | Issue Tracker | Chat Why

SciPipe 972 Dec 25, 2022
A command line tool that builds and (re)starts your web application everytime you save a Go or template fileA command line tool that builds and (re)starts your web application everytime you save a Go or template file

# Fresh Fresh is a command line tool that builds and (re)starts your web application everytime you save a Go or template file. If the web framework yo

null 0 Nov 22, 2021
A small CLI tool to check connection from a local machine to a remote target in various protocols.

CHK chk is a small CLI tool to check connection from a local machine to a remote target in various protocols.

null 26 Oct 10, 2022
Commandline tool to generate Cistercian numerals

cistercian Commandline tool to generate Cistercian numerals. Installation go get github.com/rhardih/cistercian Example usage Text $ cistercian 7323

René Hansen 42 Sep 30, 2022
A commandline tool to resolve URI Templates expressions as specified in RFC 6570.

URI Are you tired to build, concat, replace URL(s) (via shell scripts sed/awk/tr) from your awesome commandline pipeline? Well! here is the missing pi

Luca Sepe 17 Jun 9, 2021
tigrfont is a commandline tool for creating bitmap font sheets for TIGR from TTF or BDF font files.

tigrfont - bitmap font sheet generator for TIGR tigrfont is a commandline tool for creating bitmap font sheets for TIGR from TTF or BDF font files. TI

Erik Agsjö 10 Dec 5, 2022
A Go library and common interface for running local and remote commands

go-runcmd go-runcmd is a Go library and common interface for running local and remote commands providing the Runner interface which helps to abstract

AUCloud 1 Nov 25, 2021
Slack remote terminal - execute commands on remote host using slack slash command

slackRT Slack remote terminal - execute commands on remote host using slack slash command Installation Go to api.slack.com/apps and sign in and create

null 2 Jul 12, 2022
Testing local and remote shell commands in Go

Testing local and remote shell commands in Go. This is an (intentionally simplified) example of how unix shell commands can be unit-tested in Go. The

Anton 5 Nov 30, 2021
Waiton - Commandline for executing command and waiting on output

waiton Commandline for executing command and waiting on output Output of waiton

Andreas Bergmeier 0 Feb 4, 2022
Commandline Utility To Create Secure Password Hashes (scrypt / bcrypt / pbkdf2)

passhash Create Secure Password Hashes with different algorithms. I/O format is base64 conforming to RFC 4648 (also known as url safe base64 encoding)

Michael Gebetsroither 16 Oct 10, 2022
An alternative syntax to generate YAML (or JSON) from commandline

yo An alternative syntax to generate YAML (or JSON) from commandline. The ultimate commanline YAML (or JSON) generator! ... I'm kidding of course! but

Luca Sepe 10 Jul 30, 2022
Teardown API for Commandline Based Applications

Building go build -ldflags "-s -w" -o ./build/api.exe ./ Get the latest XML from https://www.teardowngame.com/modding/api.xml Commands help list searc

Dan 4 Mar 1, 2022
NYAGOS - The hybrid Commandline Shell between UNIX & DOS

The Nihongo Yet Another GOing Shell English / Japanese NYAGOS is the commandline-shell written with the Programming Language GO and Lua. There are som

nyaos.org 305 Dec 30, 2022
Curried commandline

curry Install $ go install github.com/lambdasawa/[email protected] $ brew tap lambdasawa/tap $ brew install lambdasawa/tap/curry Usage Basic usage. $ curry

Tsubasa Irisawa 3 Dec 10, 2021
A simple golang marshaller from commandline to a struct

flagmarshal SYNOPSIS A simple golang marshaller from commandline to a struct ParseFlags(structptr interface{}) error DESCRIPTION Very simple implement

null 0 Jan 22, 2022
:zap: boilerplate template manager that generates files or directories from template repositories

Boilr Are you doing the same steps over and over again every time you start a new programming project? Boilr is here to help you create projects from

Tamer Tas 1.5k Jan 6, 2023
Sipexer - Modern and flexible SIP (RFC3261) command line tool

sipexer Modern and flexible SIP (RFC3261) command line tool. Overview sipexer is

Daniel-Constantin Mierla 149 Jan 1, 2023
Chore is a elegant and simple tool for executing common tasks on remote servers.

Chore is a tool for executing common tasks you run on your remote servers. You can easily setup tasks for deployment, commands, and more.

Ahmed waleed 39 May 20, 2022