{"id":21725516,"url":"https://github.com/jameswoolfenden/consul-template-by-example","last_synced_at":"2026-04-28T13:31:44.905Z","repository":{"id":81359111,"uuid":"127789957","full_name":"JamesWoolfenden/consul-template-by-example","owner":"JamesWoolfenden","description":"consul-template-by-example","archived":false,"fork":false,"pushed_at":"2019-01-11T22:00:16.000Z","size":11,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-25T19:28:20.321Z","etag":null,"topics":["consul","consul-template","development"],"latest_commit_sha":null,"homepage":null,"language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/JamesWoolfenden.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-04-02T17:35:26.000Z","updated_at":"2019-01-11T22:00:18.000Z","dependencies_parsed_at":"2023-07-11T10:35:51.994Z","dependency_job_id":null,"html_url":"https://github.com/JamesWoolfenden/consul-template-by-example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JamesWoolfenden%2Fconsul-template-by-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JamesWoolfenden%2Fconsul-template-by-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JamesWoolfenden%2Fconsul-template-by-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JamesWoolfenden%2Fconsul-template-by-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JamesWoolfenden","download_url":"https://codeload.github.com/JamesWoolfenden/consul-template-by-example/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244706500,"owners_count":20496570,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["consul","consul-template","development"],"created_at":"2024-11-26T03:18:21.645Z","updated_at":"2026-04-28T13:31:44.866Z","avatar_url":"https://github.com/JamesWoolfenden.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Consul template: By Example\r\n\r\nThis is a very simple example shows how to use consul and consul-template to get data in and out, and how to handle missing and default values. The consul setup is only for development purposes.\r\n\r\nDownload this repository [here](https://github.com/JamesWoolfenden/consul-template-by-example)\r\n\r\n## Set-up the tools\r\n\r\nRun both shell scripts (_setup.sh_ and _setup-consul.sh_) to get the tools consul and consul-template. The install examples assume linux but this could be any supported platform as long as the tools are installed in your path.\r\n\r\n## Start/Spawn Consul\r\n\r\n`consul agent -dev \u0026`\r\n\r\nThere's an example template file called _miss.tpl_. This looks like:\r\n\r\n```jinja2\r\nKey:Foo:{{key \"foo\"}}\r\nMissingKey:{{if keyExists \"MissingKey\"}}{{key \"MissingKey\"}}{{else}}nothing{{end}}\r\nDefaultValue:{{keyOrDefault \"Duffer\" \"\"}}\r\n```\r\n\r\nConsul-template uses the Go templating format- curly brackets the rest of the file is treated as text. The first line is a regular KV retrieval, the second line shows how to cope with missing values and the last line for default values.\r\n\r\nFirst we'll add some data to Consul.\r\n\r\n`consul kv put foo bar`\r\n\r\nThen when we run consul-template:\r\n\r\n`consul-template -template miss.tpl:miss.out -once`\r\n\r\nThe -once option \"Do not run the process as a daemon\".\r\n\r\nCheck the contents of the **miss.out** file.\r\n\r\n```jina2\r\nKey:Foo:bar\r\nMissingKey:nothing\r\nDefaultValue:\r\n```\r\n\r\nThen we'll add a value for _MissingKey_ variable.\r\n\r\n`consul kv put MissingKey Time`\r\n\r\nand retry:\r\n`consul-template -template miss.tpl:miss.out -once`\r\n\r\n**miss.out** now becomes:\r\n\r\n```jinja2\r\nKey:Foo:bar\r\nMissingKey:Time\r\nDefaultValue:\r\n```\r\n\r\nSo there you have it a pretty basic example for using some of the basics behind consul and consul-template as a KV store.\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjameswoolfenden%2Fconsul-template-by-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjameswoolfenden%2Fconsul-template-by-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjameswoolfenden%2Fconsul-template-by-example/lists"}