Skip to content

Instantly share code, notes, and snippets.

@tjhop
Created May 8, 2023 03:01
Show Gist options
  • Save tjhop/5ec0f0c10d16183fb73c7720dccdce12 to your computer and use it in GitHub Desktop.
Save tjhop/5ec0f0c10d16183fb73c7720dccdce12 to your computer and use it in GitHub Desktop.
~/go/src/github.com/tjhop/mango (main [ ]) -> cat test/mockup/inventory/hosts/testbox/variables
mango_host_template_var="Hi, I'm a host variable!"
mango_host_var_for_override="This is the original host variable content."
~/go/src/github.com/tjhop/mango (main [ ]) -> cat test/mockup/inventory/modules/test-template/variables
mango_module_template_var="Hi, I'm a module variable!"
mango_host_var_for_override="Module has updated host var!"
~/go/src/github.com/tjhop/mango (main [ ]) -> cat test/mockup/inventory/modules/test-template/apply
#!/usr/bin/env bash
FILE="/tmp/$(basename ${0%/*})-$$"
cat > ${FILE} <<EOF
Testing templating!
Printing all variables available, via template
-------------------
Printing host variables:
{{- range $k, $v := .HostVars }}
{{ $k }} : {{ $v }}
{{- end }}
-------------------
Printing module variables:
{{- range $k, $v := .ModuleVars }}
{{ $k }} : {{ $v }}
{{- end }}
-------------------
Printing all variables (merged, where module variables override host variables):
{{- range $k, $v := .Vars }}
{{ $k }} : {{ $v }}
{{- end }}
-------------------
Done.
EOF
~/go/src/github.com/tjhop/mango (main [ ]) -> cat /tmp/test-template-1359274
Testing templating!
Printing all variables available, via template
-------------------
Printing host variables:
mango_host_template_var : Hi, I'm a host variable!
mango_host_var_for_override : This is the original host variable content.
-------------------
Printing module variables:
mango_host_var_for_override : Module has updated host var!
mango_module_template_var : Hi, I'm a module variable!
-------------------
Printing all variables (merged, where module variables override host variables):
mango_host_template_var : Hi, I'm a host variable!
mango_host_var_for_override : Module has updated host var!
mango_module_template_var : Hi, I'm a module variable!
-------------------
Done.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment