saltstack / salt

Software to automate the management and configuration of any infrastructure or application at scale. Install Salt from the Salt package repositories here:
https://docs.saltproject.io/salt/install-guide/en/latest/
Apache License 2.0
14.23k stars 5.49k forks source link

No way to debug templates over salt-ssh #50196

Open max-arnold opened 6 years ago

max-arnold commented 6 years ago

Description of Issue/Question

The recommended ways to debug templates are (as seen in the Slack chat):

salt 'example.com' slsutil.renderer /path/to/file.jinja 'jinja'
salt 'example.com' cp.get_template salt://path/to/template /dev/stdout template=jinja

Unfortunately, I was unable to make it work over salt-ssh:

salt-ssh -l debug example.com slsutil.renderer path='salt://test.sls' default_renderer='jinja'
...
[DEBUG   ] Could not LazyLoad slsutil.renderer: 'slsutil.renderer' is not available.
...
salt-ssh example.com cp.get_template salt://test.sls /dev/stdout template=jinja

example.com:
    ----------
    retcode:
        0
    stderr:
        Traceback (most recent call last):
          File "/var/tmp/.root_7e26e1_salt/salt-call", line 15, in <module>
            salt_call()
          File "/var/tmp/.root_7e26e1_salt/py3/salt/scripts.py", line 400, in salt_call
            client.run()
          File "/var/tmp/.root_7e26e1_salt/py3/salt/cli/call.py", line 57, in run
            caller.run()
          File "/var/tmp/.root_7e26e1_salt/py3/salt/cli/caller.py", line 134, in run
            ret = self.call()
          File "/var/tmp/.root_7e26e1_salt/py3/salt/cli/caller.py", line 212, in call
            ret['return'] = func(*args, **kwargs)
          File "/var/tmp/.root_7e26e1_salt/py3/salt/modules/cp.py", line 335, in get_template
            **kwargs)
          File "/var/tmp/.root_7e26e1_salt/py3/salt/fileclient.py", line 782, in get_template
            **kwargs
          File "/var/tmp/.root_7e26e1_salt/py3/salt/utils/templates.py", line 167, in render_tmpl
            tmplstr = tmplsrc.read()
        AttributeError: 'bool' object has no attribute 'read'
    stdout:

Third way also doesn't work:

salt-ssh example.com cp.get_file salt://test.sls /dev/stdout template=jinja

example.com:
    False

Salt version 2018.3.2 on Py3.

The question is: what is the best (and documented) way to debug templates, which works consistently across salt, salt-call and salt-ssh (and maybe salt-run)?

dwoz commented 6 years ago

@max-arnold Thank you for reporting this.

max-arnold commented 5 years ago

Any clues on how to fix this?

limakzi commented 5 years ago
.venv ❯ salt --version
salt 2019.2.0 (Fluorine)

I faced this problem yesterday. It highly impacts local development process.

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.

max-arnold commented 4 years ago

Still valid

stale[bot] commented 4 years ago

Thank you for updating this issue. It is no longer marked as stale.

amendlik commented 4 years ago

I can work on a fix if the @dwoz or someone at Salt can offer some guidance.

sagetherage commented 4 years ago

@amendlik looking to find someone who can give that guidance, thank you!

andreasnuesslein commented 3 years ago

@amendlik so I looked into the code a bit as well, if you're still interested in takling this ( / but also writing this here as a note to myself a bit):

i found out that

[DEBUG   ] Could not LazyLoad slsutil.renderer: 'slsutil.renderer' is not available.
[DEBUG   ] Performing shimmed, blocking command as follows:
slsutil.renderer /tmp/map.py

basically means: "i did not find a ssh/wrapper for slsutil, i will instead copy a kind of shim over to the node and try to execute everything there"

the shimmed version will actually work if that target file is on the host; so my test here with /tmp/map.py worked because i threw that file over onto that node. however salt:// paths will obviously not work.

a starting point to implement that slsutil to make it LazyLoad-able is the folder salt/client/ssh/wrapper/, create a file salt/client/ssh/wrapper/slsutil.py:

import logging

log = logging.getLogger(__name__)

def renderer(path=None, string=None, default_renderer="jinja|yaml", **kwargs):
    log.info("whoohoo, we found the starting point")

and then I suppose gather inspiration from the other salt/client/ssh/wrappers