if you put a flag like vvv together with dvar definition, you will see the evaluated result will be printed in that verbose level for you to debug or trace problem
vars:
ns: prod
pod_name: web_app
ha: true
age: 34
old: 54
admins: [tom, jason, alice]
managers:
- tom
- jason
- alice
fieldnames:
name-with-dash: |
this_is_a_field_with_dash: you will have to use index func to access the field
note: direct access this field will trigger template rendering error
#we intend to access the dynamic value of the pod_name, which has got value of web_app
#this is an example of indirect access of varname
where_is_my_deploy: pod_name
dvars:
- name: instance_full_name
value: "{{.ns}}-{{.pod_name}}"
- name: var_space_not_trimmed
value: "{{.ns}} - {{.pod_name}}"
- name: var_space_trimmed
value: "{{.ns -}} - {{- .pod_name}}"
- name: var_commented
value: "{{/*this is funny*/}} {{.ns}}-{{.pod_name}}"
- name: var_commented_trimmed
value: "{{- /*this is funny*/ -}}{{.ns}}-{{.pod_name}}"
- name: var_with_if
value: "{{if .ha }}{{.ns}}-{{.pod_name}}-HA{{end}}"
#extra: {{if pipeline}} T1 {{else if pipeline}} T0 {{end}}
- name: var_with_range
value: "{{range .managers}} x {{end}}"
flags: [vvvv]
- name: var_with_range_item
value: "{{range $x:=.managers}} {{$x}} {{end}}"
flags: [vvvv]
- name: var_with_range_item_simpler
value: "{{range .managers}} {{.}} {{end}}"
flags: [vvvv]
- name: var_with_ifelse
value: "{{if .ha }}{{.ns}}-{{.pod_name}}-HA{{else}}{{.ns}}-{{.pod_name}}{{end}}"
- name: var_with_ifelse_multilines
value: " {{if .ha }} {{.ns}}-{{.pod_name}}-HA {{else}} {{.ns}}-{{.pod_name}} {{end}}"
- name: var_with_not
value: "{{if not .ha }}{{.ns}}-{{.pod_name}}{{else}}{{.ns}}-{{.pod_name}}{{end}}"
flags: [toObj]
- name: var_length
value: "{{len .var_with_not}}"
- name: var_with_or
desc: return the first non-empty argument or the last argument
value: "{{or .ns .pod_name}}"
- name: var_with_print
value: "{{print .ns .pod_name}}"
- name: var_test_log_auto_print
value: "{{print .ns .pod_name}}"
flags: [vvvv, toObj]
- name: var_with_and
desc: and x y behaves as if x then y else x
value: "{{and .ns .pod_name}}"
flags: [vvvv]
- name: var_slice_index
value: "{{ index .admins 1 }}"
flags: [vvvv]
- name: out_of_normal_field_name
value: '{{ index .fieldnames "name-with-dash" }}'
flags: [vvvv]
- name: indirect_var_reference
value: '{{ index . ".where_is_my_deploy" }}'
flags: [vvvv]
- name: var_slice
value: "{{ slice .managers 1 2}}"
flags: [vvvv]
- name: var_equal
value: "{{ eq .ns .pod_name }}"
flags: [vvvv]
- name: var_not_equal
value: "{{ ne .ns .pod_name }}"
flags: [vvvv]
- name: var_not_equal_another_way
value: "{{ not (eq .ns .pod_name) }}"
flags: [vvvv]
- name: var_greater
value: "{{ gt .ns .pod_name }}"
flags: [vvvv]
- name: var_greater_and_equal
value: "{{ ge .old .age }}"
flags: [vvvv]
- name: var_greater_and_equal
value: "{{ if ge .old .age }}hello{{end}}"
flags: [vvvv]
- name: var_use_and_operator
value: '{{ and (eq .ns "prod") (ne .age 35)}}'
flags: [v]
- name: var_use_or_operator
value: '{{ or (eq .ns "prod") (ne .age 35)}}'
flags: [v]
- name: var_concat_values
value: '{{ printf "%s: %d years old" .pod_name .age}}'
flags: [v]
#extra: lt, le
- name: template_def
value: |
{{define "T1"}}ONE{{end}}
{{define "T2"}}TWO{{end}}
{{define "T3"}}{{template "T1"}} {{template "T2"}}{{end}}
{{template "T3"}}"
flags: [vvvv]
tasks:
- name: task
task:
- func: shell
do:
- echo "{{.instance_full_name}}"
- echo "{{.var_space_not_trimmed}}"
- echo "{{.var_space_trimmed}}"
- echo "{{.var_commented}}"
- echo "{{.var_commented_trimmed}}"
- echo "{{.var_with_if}}"
- echo "{{.var_with_ifelse}}"
- echo "{{.var_with_ifelse_multilines}}"
- echo "{{.var_with_not}}"
- echo "{{.var_with_not_object}}"
- echo "{{.var_length}}"
- echo "{{.var_with_or}}"
- echo "{{.var_with_print}}"
- echo "check the value of other dvar using vvvv flag print out"
loading [Config]: ./tests/functests/upconfig.yml
Main config:
Version -> 1.0.0
RefDir -> ./tests/functests
WorkDir -> cwd
AbsWorkDir -> /up_project/up
TaskFile -> c0036
Verbose -> vvv
ModuleName -> self
ShellType -> /bin/sh
MaxCallLayers -> 8
Timeout -> 3600000
MaxModuelCallLayers -> 256
EntryTask -> task
ModRepoUsernameRef ->
ModRepoPasswordRef ->
work dir: /up_project/up
-exec task: task
loading [Task]: ./tests/functests/c0036
module: [self], instance id: [dev], exec profile: []
profile - envVars:
(*core.Cache)({
})
dvar> var_with_range:
" x x x "
-
x x x
dvar> var_with_range_item:
" tom jason alice "
-
tom jason alice
dvar> var_with_range_item_simpler:
" tom jason alice "
-
tom jason alice
dvar> var_test_log_auto_print:
"prodweb_app"
-
prodweb_app
dvar[object]> var_test_log_auto_print_object:
"prodweb_app"
dvar> var_with_and:
"web_app"
-
web_app
dvar> var_slice_index:
"jason"
-
jason
dvar> out_of_normal_field_name:
"this_is_a_field_with_dash: you will have to use index func to access the field\nnote: direct access this field will trigger template rendering error\n"
-
this_is_a_field_with_dash: you will have to use index func to access the field
note: direct access this field will trigger template rendering error
dvar> indirect_var_reference:
"None"
-
None
dvar> var_slice:
"[jason]"
-
[jason]
dvar> var_equal:
"false"
-
false
dvar> var_not_equal:
"true"
-
true
dvar> var_not_equal_another_way:
"true"
-
true
dvar> var_greater:
"false"
-
false
dvar> var_greater_and_equal:
"true"
-
true
dvar> var_greater_and_equal:
"hello"
-
hello
dvar> var_use_and_operator:
"true"
-
true
dvar> var_use_or_operator:
"true"
-
true
dvar> var_concat_values:
"web_app: 34 years old"
-
web_app: 34 years old
dvar> template_def:
"\n\n\nONE TWO\"\n"
-
ONE TWO"
Task1: [task ==> task: ]
-Step1:
self: final context exec vars:
(*core.Cache)({
"var_test_log_auto_print_object": "prodweb_app",
"var_space_trimmed": "prod-web_app",
"var_with_not_object": "prod-web_app",
"var_with_range_item": " tom jason alice ",
"var_commented": " prod-web_app",
"admins": {
"tom",
"jason",
"alice"
},
"up_runtime_task_layer_number": 0,
"old": 54,
"var_with_or": "prod",
"var_space_not_trimmed": "prod - web_app",
"var_with_if": "prod-web_app-HA",
"ns": "prod",
"var_with_and": "web_app",
"ha": true,
"var_equal": "false",
"out_of_normal_field_name": "this_is_a_field_with_dash: you will have to use index func to access the field\nnote: direct access this field will trigger template rendering error\n",
"age": 34,
"var_slice_index": "jason",
"pod_name": "web_app",
"var_use_or_operator": "true",
"indirect_var_reference": "None",
"var_use_and_operator": "true",
"var_length": "12",
"var_with_not": "prod-web_app",
"var_greater": "false",
"managers": {
"tom",
"jason",
"alice"
},
"var_with_range_item_simpler": " tom jason alice ",
"instance_full_name": "prod-web_app",
"fieldnames": {
"name-with-dash": "this_is_a_field_with_dash: you will have to use index func to access the field\nnote: direct access this field will trigger template rendering error\n"
},
"var_with_ifelse_multilines": " prod-web_app-HA ",
"var_concat_values": "web_app: 34 years old",
"var_not_equal_another_way": "true",
"var_slice": "[jason]",
"where_is_my_deploy": "pod_name",
"var_with_print": "prodweb_app",
"var_with_ifelse": "prod-web_app-HA",
"var_not_equal": "true",
"template_def": "\n\n\nONE TWO\"\n",
"var_test_log_auto_print": "prodweb_app",
"var_greater_and_equal": "hello",
"var_commented_trimmed": "prod-web_app",
"var_with_range": " x x x "
})
cmd( 1):
echo "{{.instance_full_name}}"
-
prod-web_app
-
.. ok
cmd( 2):
echo "{{.var_space_not_trimmed}}"
-
prod - web_app
-
.. ok
cmd( 3):
echo "{{.var_space_trimmed}}"
-
prod-web_app
-
.. ok
cmd( 4):
echo "{{.var_commented}}"
-
prod-web_app
-
.. ok
cmd( 5):
echo "{{.var_commented_trimmed}}"
-
prod-web_app
-
.. ok
cmd( 6):
echo "{{.var_with_if}}"
-
prod-web_app-HA
-
.. ok
cmd( 7):
echo "{{.var_with_ifelse}}"
-
prod-web_app-HA
-
.. ok
cmd( 8):
echo "{{.var_with_ifelse_multilines}}"
-
prod-web_app-HA
-
.. ok
cmd( 9):
echo "{{.var_with_not}}"
-
prod-web_app
-
.. ok
cmd(10):
echo "{{.var_with_not_object}}"
-
prod-web_app
-
.. ok
cmd(11):
echo "{{.var_length}}"
-
12
-
.. ok
cmd(12):
echo "{{.var_with_or}}"
-
prod
-
.. ok
cmd(13):
echo "{{.var_with_print}}"
-
prodweb_app
-
.. ok
cmd(14):
echo "check the value of other dvar using vvvv flag print out"
-
check the value of other dvar using vvvv flag print out
-
.. ok
. ok