github.com/upcmd/up@v0.8.1-0.20230108151705-ad8b797bf04f/tests/functests/c0023.yml (about)

     1  doc_meta: |
     2    folder: dvars
     3    title: dvars intro
     4    head: |
     5      dvar stands for dynamic var. As suggested by the naming, dvar is like a calculated variable during runtime, we call this behavior as expansion. A dvar's value is expressed using golang template, it could be the case that a expanded result contains another template variable, so that you will need to expand it again.
     6  
     7      By default the expand level is 1, but you can custmise it to be multiple depending on your own needs
     8  
     9      We use array to configure a entry of dvar item, the sequence matters as the value of dvar will be evaluated sequentially, the later one will need to reference to the evaluated value of another dvar
    10  
    11      A validation rule is that the name of a dvar should should not contiain "-" as it will conflict with golang template var naming
    12  
    13    sections:
    14      - title: Note
    15        content: |
    16          Please take note the demo cases that use multiple expansion, it is dynamic on dynamic and it is usful in certain cases. Please read the self explanation of the description in dvar config
    17  
    18      - title: Demo
    19        log: yes
    20  
    21  notes:
    22    goal:
    23      - to show dynamic vars
    24      - dynamic vars suppport customizable level of expanding
    25      - default expand level is 1
    26      - use array so that sequence is known and reduce complexity and mess
    27      - |
    28        dvar name should not contiain - as it will conflict
    29        with golang template var naming
    30  
    31  vars:
    32    student: Tom
    33    gender: Male
    34    school: Sydney Grammar
    35    a1: a1->{{.b2}}
    36    b2: b2->{{.c3}}
    37    c3: c3->{{.d4}}
    38    d4: d4->{{.student}}
    39  
    40  dvars:
    41    - name: from
    42      value: "{{.school}}"
    43      desc: |
    44        default expanding level is 1
    45        you will have to quote it if it starts the value of bracket since yaml uses it
    46  
    47    - name: sex
    48      value: "{{.gender}}"
    49      expand: 1
    50  
    51    - name: dependon_vars
    52      value: "{{.sex}}"
    53  
    54    - name: dependon_var_and_dvar
    55      value: "{{.student}}-{{.sex}}"
    56      desc: this is still 1 level expanding as .sex must be rendered and merged into runtimevars
    57  
    58    - name: multple_render_var_level3
    59      value: multple-render-var-> {{.b2}}
    60      desc: |
    61        you don't have to quote as bracket is not the start of the value and not conflict with yaml
    62  
    63    - name: multple_render_var_level3_with_expand2
    64      value: multple-render-var-> {{.b2}}
    65      expand: 2
    66  
    67    - name: multple_render_var_level3_with_expand3
    68      value: multple-render-var-> {{.b2}}
    69      expand: 3
    70  
    71    - name: multple_render_var_level3_with_expand4
    72      value: multple-render-var-> {{.b2}}
    73      expand: 4
    74  
    75    - name: multple_render_var_level5
    76      value: multple-render-var-> {{.a1}}
    77      expand: 5
    78  
    79  #  - name: invalid-name
    80  #    value: multple-render-var-> {{.a1}}
    81  
    82  tasks:
    83  
    84    - name: task
    85      task:
    86        -
    87          func: shell
    88          do:
    89            - echo "student=>{{.student}}"
    90            - echo "a1=> a1->{{.b2}}"
    91            - echo "from->{{.from}}"
    92            - echo "sex->{{.sex}}"
    93            - echo "dependon_vars->{{.dependon_vars}}"
    94            - echo "dependon_var_and_dvar->{{.dependon_var_and_dvar}}"
    95            - echo "multple_render_var_level3->{{.multple_render_var_level3}}"
    96            - echo "multple_render_var_level4->{{.multple_render_var_level4}}"