Skip to main content

Salt Extension for interacting with Yte

Project description

=========== salt-ext-yte

A Salt “renderer” plugin implementing the YTE (YAML-Template-Engine) renderer for SaltStack.
Combines plain YAML with embedded template logic (variables, conditionals, loops, custom definitions) without leaving YAML.

Overview

The YTE renderer lets you write Salt states and Pillar data in a single YAML-first syntax, with a small set of directives (__variables__, __definitions__) for setup and Python snippets. It folds into the normal Salt render pipeline and works alongside Jinja/YAML.

Features

  • YTE renderer plugin for SaltStack (loadable via renderer: yte in your Salt config)
  • Embedded variables: define defaults, derive from grains/pillar, use Python expressions
  • Custom definitions: write Python helper functions or blocks and have them execute during render
  • Standard Salt context: access salt, grains, pillar, opts, __proxy__, saltenv, sls
  • Fall-through: if no YTE directives are present, it behaves like plain YAML

Requirements

  • SaltStack ≥ 3006
  • Python 3.10+

Installation

  1. Install the plugin via salt-pip:

    .. code-block:: bash

    salt * pip.install salt-ext-yte

  2. Enable the renderer in /etc/salt/master and/or /etc/salt/minion:

    .. code-block:: yaml

    renderer: - yaml_jinja - yte - yaml

  3. Restart the Salt daemons:

    .. code-block:: bash

    systemctl restart salt-master systemctl restart salt-minion

YTE Constructs

Within any .sls or Pillar file rendered by YTE, you can use two special top-level keys:

  1. __variables__
    A mapping of names to Python expressions (prefixed with ?). These expressions are evaluated once, and their results are bound as local variables.

  2. __definitions__
    A list of Python code blocks. Each block can define helper functions or mutate the variable namespace.

Example vars.sls


.. code-block:: yaml

    #!yte

    __variables__:
        ray: ?pillar.get("ray", {})
        head: ?ray.get("head", grains["master"])
        port: ?ray.get("port", 6379)
        python: ?grains["pythonexecutable"]
        win: ?(grains["os"] == "Windows")
        path: ?("C:\\ray_venv" if win else "/opt/ray_venv")
        address: ?ray.get("head_address", "")

   __definitions__:
     - |
       def reachable():
           salt["mine.update"]()
           for ip in salt["mine.get"](head, "network.fqdns"):
               if salt["network.ping"](ip, return_boolean=True, timeout=3):
                   return f"{ip}:{port}"
           return "auto"

       if not address:
           address = reachable()

State Usage Examples
--------------------

Installing ray wiht `relenv`:

.. code-block:: sls

    #!jinja|yte
    {% include 'vars.sls' %}

    relenv:
      pip.installed:
        - bin_env: ?python
        - upgrade: True

    relenv_fetch:
      cmd.run:
        - name: ?f'"{python}" -m relenv fetch'
        - require:
          - pip: relenv

   ray:
     pip.installed:
       - pkgs:
         - ?if is_head:
             "ray[default]"
           ?else:
             ray
       - bin_env: ?python

Development
-----------

1. **Install** dev dependencies:

   .. code-block:: bash

      pip install -r requirements/tests.txt

2. **Test**:

   .. code-block:: bash

      pytest

3. **Lint**:

   .. code-block:: bash

      pip install pre-commit
      pre-commit run -av

Contributing
------------

1. Fork and branch from `master`.  
2. Add tests for any new syntax.  
3. Open a PR; reference relevant issue(s); follow SaltStack plugin guidelines.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

saltext_yte-1.0.0-py2.py3-none-any.whl (6.2 kB view details)

Uploaded Python 2Python 3

File details

Details for the file saltext_yte-1.0.0-py2.py3-none-any.whl.

File metadata

  • Download URL: saltext_yte-1.0.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for saltext_yte-1.0.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 cadc4138018955f284d1fca7c46be7a2200a0cb85e253ab6cd9a0a19dd5bc6b0
MD5 e8da92f89fb48c25c16c37348aa1ade4
BLAKE2b-256 c30874022d1184b51c546948d12b0e40530330d944e12af368ac7718f6368c4c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page