| Server IP : 198.38.94.13 / Your IP : 216.73.217.33 Web Server : Apache System : Linux d4744.dxb1.stableserver.net 5.14.0-611.49.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Apr 21 16:39:08 EDT 2026 x86_64 User : revivere ( 1140) PHP Version : 8.2.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/ |
Upload File : |
"""
Yaml helper module for troubleshooting yaml
.. versionadded:: 3005
:depends: yamllint >= 1.20.0
"""
import logging
import salt.utils.versions
log = logging.getLogger(__name__)
__virtualname__ = "yaml"
try:
import salt.utils.yamllint
HAS_LINT = True
except ImportError:
HAS_LINT = False
def __virtual__():
if HAS_LINT:
if salt.utils.yamllint.has_yamllint():
version = salt.utils.yamllint.version()
version_cmp = salt.utils.versions.version_cmp(version, "1.20.0")
else:
return (False, "yamllint not installed")
if version_cmp >= 0:
return __virtualname__
else:
return (False, "yamllint below 1.20.0, please pip install a newer version")
else:
return (False, "yamllint not installed")
def lint(source, saltenv=None, pre_render=None, **kwargs):
"""
lint the output after detecting a sucsessful render.
:param str source: managed source file
:param str saltenv: the saltenv to use, defaults
to minions enviroment or base if not set
:param str pre_render: The render options passed to
slsutil.renderer other wise file is cached and loaded as stream
CLI Example:
.. code-block:: bash
salt '*' yaml.lint salt://example/bad_yaml.sls
"""
if saltenv is None:
saltenv = __salt__["config.get"]("saltenv", "base")
if saltenv is None:
saltenv = "base"
if pre_render is None:
cache = __salt__["cp.cache_file"](source, saltenv)
if cache is False:
return (False, "Template was unable to be cached")
with __utils__["files.fopen"](cache, "r") as yaml_stream:
yaml_out = yaml_stream.read(-1)
else:
kwargs.update({"saltenv": saltenv})
yaml_out = __salt__["slsutil.renderer"](
path=source, default_renderer=pre_render, **kwargs
)
return salt.utils.yamllint.lint(yaml_out)