2023-11-13 09:33:28 -05:00
|
|
|
{#
|
2024-01-29 10:49:54 -05:00
|
|
|
SPDX-FileCopyrightText: 2023 - 2024 Benjamin Grande M. S. <ben.grande.b@gmail.com>
|
2023-11-13 09:33:28 -05:00
|
|
|
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
#}
|
|
|
|
|
|
|
|
{#
|
|
|
|
Usage:
|
|
|
|
1: Import this template:
|
|
|
|
{% from 'utils/macros/clone-template.sls' import clone_template -%}
|
|
|
|
|
|
|
|
2: Set template to clone from and the clone name:
|
|
|
|
{{ clone_template('debian-minimal', sls_path) }}
|
|
|
|
#}
|
|
|
|
|
2024-01-26 16:46:36 -05:00
|
|
|
{% macro clone_template(source, name, prefix='tpl-', include_create=True) -%}
|
2023-11-13 09:33:28 -05:00
|
|
|
|
2024-02-16 18:03:19 -05:00
|
|
|
## Avoid conflicting 'include' ID.
|
|
|
|
{% if source is iterable and (source is not string and source is not mapping) -%}
|
|
|
|
|
|
|
|
{%- import source[0] ~ "/template.jinja" as template -%}
|
|
|
|
{% set source_create = source | map('regex_replace', '$', '.create') | list %}
|
|
|
|
{% if include_create -%}
|
|
|
|
include: {{ source_create }}
|
|
|
|
{% endif %}
|
|
|
|
{% set source = source[0] -%}
|
2023-11-13 09:33:28 -05:00
|
|
|
|
2024-02-16 18:03:19 -05:00
|
|
|
{% else %}
|
|
|
|
|
|
|
|
{%- import source ~ "/template.jinja" as template -%}
|
2024-01-26 16:46:36 -05:00
|
|
|
{% if include_create -%}
|
2023-11-13 09:33:28 -05:00
|
|
|
include:
|
|
|
|
- {{ source }}.create
|
2024-02-16 18:03:19 -05:00
|
|
|
{% endif %}
|
|
|
|
|
|
|
|
{% endif %}
|
2024-01-12 11:22:58 -05:00
|
|
|
|
|
|
|
"{{ prefix }}{{ name }}-clone":
|
2023-11-13 09:33:28 -05:00
|
|
|
qvm.clone:
|
|
|
|
- require:
|
|
|
|
- sls: {{ source }}.create
|
|
|
|
- source: {{ template.template }}
|
2024-01-12 11:22:58 -05:00
|
|
|
- name: {{ prefix }}{{ name }}
|
2023-11-13 09:33:28 -05:00
|
|
|
|
|
|
|
{% endmacro -%}
|