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.22k stars 5.49k forks source link

No ability to use custom salt jinja2 filter in custom cloud deploy scripts #52442

Open rf-vivanovs opened 5 years ago

rf-vivanovs commented 5 years ago

Description of Issue/Question

When writing deploy scripts vm, opt, and minion dicts are available. minion is str, but vm and opt are dicts, and we can't dump them directly.

The problem is that if you need to dump/pass information that is json/yaml, you don't have the ability to do that from the deployer script, because no json/yaml filter is available.

I'm not sure if it is intended or not, but would be nice to have an ability to use them.

Setup

I have a custom cloud deployer with "custom" opts:

minion:
  master: xxx
  grains: {}
env-specific-settings:
  some_yaml:
    more_yaml:
      - more_yaml

Then in my custom deployer script I have (just an example)

cat > /tmp/dump <<EOF
{{ opts }}
{{ opts.my_value }}
{{ opts | yaml(False) }}
EOF

Steps to Reproduce Issue

If you deploy a VM with the custom deployer script you will see an error and traceback:

                    File "/usr/lib/python2.7/site-packages/jinja2/environment.py", line 742, in handle_exception
                      reraise(exc_type, exc_value, tb)
                    File "<unknown>", line 14, in template
                  TemplateAssertionError: no filter named 'yaml
Runner function 'cloud.profile' failed.

and the raw dump of data looks like:

{u'key_cache': u'', u'regen_thin': False, u'tcp_master_workers': 4515, u'external_auth': {}, u'fileserver_backend': [u'gitfs', u'roots']....

Versions Report

Salt Version:
           Salt: 2019.2.0

Dependency Versions:
           cffi: 1.6.0
       cherrypy: Not Installed
       dateutil: Not Installed
      docker-py: Not Installed
          gitdb: 0.6.4
      gitpython: 1.0.1
          ioflo: Not Installed
         Jinja2: 2.7.2
        libgit2: Not Installed
        libnacl: Not Installed
       M2Crypto: Not Installed
           Mako: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.5.6
   mysql-python: Not Installed
      pycparser: 2.14
       pycrypto: 2.6.1
   pycryptodome: Not Installed
         pygit2: Not Installed
         Python: 2.7.5 (default, Oct 30 2018, 23:45:53)
   python-gnupg: Not Installed
         PyYAML: 3.11
          PyZMQ: 15.3.0
           RAET: Not Installed
          smmap: 0.9.0
        timelib: Not Installed
        Tornado: 4.2.1
            ZMQ: 4.1.4

System Versions:
           dist: centos 7.6.1810 Core
         locale: ANSI_X3.4-1968
        machine: x86_64
        release: 3.10.0-957.1.3.el7.x86_64
         system: Linux
        version: CentOS Linux 7.6.1810 Core
rf-vivanovs commented 5 years ago

PR for the feature: #52443

Ch3LL commented 5 years ago

thanks for the PR!!

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.

stale[bot] commented 4 years ago

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