Saltstack Official PHP Formula
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

macro.jinja 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. # Returns a generic block of values suitable for inclusion in most states.
  2. {% macro sls_block(dict, ind=4) %}
  3. {% for key, value in dict.items() %}
  4. {{ '-'|indent(ind, True) }} {{ key }}: {{ value|json() }}
  5. {% endfor %}
  6. {% endmacro %}
  7. # Serializes dicts into sequenced data
  8. {%- macro serialize(data) -%}
  9. {%- if data is mapping -%}
  10. {%- set ret = [] -%}
  11. {%- for key, value in data.items() -%}
  12. {%- set value = serialize(value)|load_json() -%}
  13. {%- do ret.append({key: value}) -%}
  14. {%- endfor -%}
  15. {%- elif data is iterable and data is not string -%}
  16. {%- set ret = [] -%}
  17. {%- for value in data -%}
  18. {%- set value = serialize(value)|load_json() -%}
  19. {%- do ret.append(value) -%}
  20. {%- endfor -%}
  21. {%- else -%}
  22. {% set ret = data %}
  23. {%- endif -%}
  24. {{ ret|json() }}
  25. {%- endmacro -%}
  26. {%- macro deserialize(data) -%}
  27. {%- if data is mapping -%}
  28. {%- set ret = odict([]) -%}
  29. {%- for key, value in data.items() -%}
  30. {%- do ret.update({key: deserialize(value)}) -%}
  31. {%- endfor -%}
  32. {%- elif data is iterable and data is not string -%}
  33. {%- if is_list_skd(data)|int() == 1 -%}
  34. {%- set ret = odict([]) -%}
  35. {%- for item in data -%}
  36. {%- for key, value in item.items() -%}
  37. {% do ret.update({key: deserialize(value)}) %}
  38. {%- endfor -%}
  39. {%- endfor -%}
  40. {%- else -%}
  41. {%- set ret = [] -%}
  42. {%- for item in data -%}
  43. {%- do ret.append(deserialize(item)) -%}
  44. {%- endfor -%}
  45. {%- endif -%}
  46. {%- else -%}
  47. {% set ret = data %}
  48. {%- endif -%}
  49. {{ ret }}
  50. {%- endmacro -%}
  51. # and is not number and is mapping and item|length() == 1
  52. {%- macro is_list_skd(list) -%}
  53. {% set ret = 0 %}
  54. {%- set skds = {'counter': 0} -%}
  55. {%- for item in list if item is mapping and item|length() == 1 -%}
  56. {%- do skds.update({'counter': (skds.counter + 1)}) -%}
  57. {%- endfor -%}
  58. {%- if skds.counter == list|length() -%}
  59. {% set ret = 1 %}
  60. {%- endif -%}
  61. {{ ret }}
  62. {%- endmacro -%}