-
Notifications
You must be signed in to change notification settings - Fork 4
/
c0027.yml
92 lines (80 loc) · 2.8 KB
/
c0027.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
doc_meta: |
folder: dvars
title: convert dvar
head: |
A dvar value is normally a string, which could be a formated yml content, then be converted to an object. This demo shows that you can use a flag: toObj to notate this dvar will be transformed to an object and registered to global runtime
sections:
- title: Rules
content: |
* you can reference to plain dvar with the string|untemplated value
* you can reference to hiera structure of a object once it is converted
* the new name of the dvar object will be: dvar_object
* the flag keepName makes the dvar keep its original name as is instead of creating dvar_object
* keepName only used and pair to toObj
- title: Demo
log: yes
notes:
goal:
- to show complex object using dynamic var
design:
- register the object into that scope's vars list
- consider a modified name of -> a_smart_guy_object to reference to
expect:
- you can reference to plain dvar with the string|untemplated value
- you can reference to hiera structure of a object in static vars
- you can reference to a dynamic converted dvar with new name -> a_smart_guy_object
- fail if expand > 1 and toObj both exist
vars:
student:
name: Tom
gender: Male
address:
suburb:
name: sydney
postcode: 2000
CBD: yes
school: Sydney Grammar
dvars:
- name: a_smart_guy
value: |
name: Tom
gender: Male
school: Sydney Grammar
flags: [toObj,]
# expand: 2
- name: school_address
desc: |
it can reference to the dvar object a_smart_guy_object has been registered from last step
value: |
address:
suburb:
name: {{.student.address.suburb.name}}
postcode: 2000
CBD: yes
school: {{.student.address.school}}
tom:
name: {{.a_smart_guy_object.name}}
flags: [toObj,]
- name: tom
desc: |
in this case, we use keepName flag to make the dvar name the same name we give. So instead we have regitered tom (yml string) and tom_object (object), we now only have tom as registered object
value: |
name: {{.a_smart_guy_object.name}}
gender: Male
school: Sydney Grammar
flags:
- toObj
- keepName
tasks:
- name: task
task:
-
func: shell
do:
- echo """a smart guy=>{{.a_smart_guy}}"""
- echo """postcode=>{{.student.address.suburb.postcode}}"""
- echo """school address {{.school_address}}"""
- echo """this guy is in =>{{.a_smart_guy_object.school}} school"""
- echo """school address object {{.school_address_object.suburb.name}}"""
- echo """school address object -> {{.school_address_object.address.suburb.name}}"""
- echo """tom - {{.tom}}"""