Saltstack Official OpenSSH Formula
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

128 行
3.5KB

  1. {#- -*- coding: utf-8 -*- #}
  2. {#- vim: ft=jinja #}
  3. {#- Get the `tplroot` from `tpldir` #}
  4. {%- set tplroot = tpldir.split("/")[0] %}
  5. {%- macro mapstack(
  6. files,
  7. defaults=None,
  8. log_prefix="libmapstack: "
  9. ) %}
  10. {#-
  11. Load YAML files in the order of `files` and merge successively the
  12. values with `defaults` if the file exists.
  13. Parameters:
  14. - `files`: list of files to load
  15. - `defaults`: default values to start the merging, they are
  16. considered built-ins
  17. - `log_prefix`: prefix used in the log outputs, by default it is
  18. `libmapstack: `
  19. Each YAML file must conform to the following layout:
  20. - a mandatory `values` key to store the configuration values
  21. - two optional keys to configure the use of `salt.slsutil.merge`
  22. - an optional `strategy` key to configure the merging strategy,
  23. for example `strategy: 'recurse'`, the default is `smart`
  24. - an optional `merge_lists` key to configure if lists should be
  25. merged or overridden for the `recurse` and `overwrite`
  26. strategies, for example `merge_lists: 'true'`
  27. #}
  28. {%- set stack = defaults | default({"values": {} }, boolean=True) %}
  29. {%- do salt["log.debug"](
  30. log_prefix
  31. ~ "built-in configuration:\n"
  32. ~ {"values": defaults | traverse("values")}
  33. | yaml(False)
  34. ) %}
  35. {%- for yaml_filename in files %}
  36. {%- do salt["log.debug"](
  37. log_prefix
  38. ~ "load configuration values from "
  39. ~ yaml_filename
  40. ) %}
  41. {%- load_yaml as yaml_values %}
  42. {%- include yaml_filename ignore missing %}
  43. {%- endload %}
  44. {%- do salt["log.debug"](
  45. log_prefix
  46. ~ "loaded configuration values from "
  47. ~ yaml_filename
  48. ~ ":\n"
  49. ~ yaml_values
  50. | yaml(False)
  51. ) %}
  52. {%- if yaml_values %}
  53. {#- Per YAML file `salt["slsutil.merge"]` options or use defaults #}
  54. {%- set _strategy = yaml_values
  55. | traverse(
  56. "strategy",
  57. defaults
  58. | traverse(
  59. "strategy",
  60. "smart"
  61. )
  62. ) %}
  63. {%- set _merge_lists = yaml_values
  64. | traverse(
  65. "merge_lists",
  66. defaults
  67. | traverse(
  68. "merge_lists",
  69. False
  70. )
  71. )
  72. | to_bool %}
  73. {#- Update only the `values`, the `salt["slsutil.merge"]` options are never updated #}
  74. {%- do stack.update(
  75. {
  76. "values": salt["slsutil.merge"](
  77. stack["values"],
  78. yaml_values
  79. | traverse("values", {}),
  80. strategy=_strategy,
  81. merge_lists=_merge_lists,
  82. )
  83. }
  84. ) %}
  85. {%- do salt["log.debug"](
  86. log_prefix
  87. ~ "merged configuration values from "
  88. ~ yaml_filename
  89. ~ ", merge: strategy='"
  90. ~ _strategy
  91. ~ "', merge_lists='"
  92. ~ _merge_lists
  93. ~ "':\n"
  94. ~ {"values": stack["values"]}
  95. | yaml(False)
  96. ) %}
  97. {%- endif %}
  98. {%- endfor %}
  99. {%- do salt["log.debug"](
  100. log_prefix
  101. ~ "final configuration values:\n"
  102. ~ {"values": stack["values"]}
  103. | yaml(False)
  104. ) %}
  105. {#- Output stack as YAML, caller should use with something like #}
  106. {#- `{%- set config = flexible_config(prefix="foo") | load_yaml %}` #}
  107. {{ stack | yaml }}
  108. {%- endmacro %}