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