salt icon indicating copy to clipboard operation
salt copied to clipboard

Cannot concatenate Jinja variable - Centos6 python2.6

Open wongster80 opened this issue 11 years ago • 3 comments

Hi,

This used to work on 2014.1.13 but fails on 2015.5.0 and 2015.5.2. I'm running Centos6.5 python2.6

state init.sls file content:
{% set TEST_SYMLINK = '/opt/test_symlink' %}

{% if 0 == salt['cmd.retcode']('test -h '~ TEST_SYMLINK ~' ') %}
{{ TEST_SYMLINK }}:
  file.symlink:
    - target: /opt/yp
    - force: True
{% endif %}


running salt-call on the state:


local:
    Data failed to compile:
----------
    Rendering SLS 'aidandev:test_state' failed: Jinja error: execve() argument 1 must be encoded string without NULL bytes, not str
Traceback (most recent call last):
  File "/usr/lib/python2.6/site-packages/salt/utils/templates.py", line 306, in render_jinja_tmpl
    output = template.render(**decoded_context)
  File "/usr/lib64/python2.6/site-packages/jinja2/environment.py", line 669, in render
    return self.environment.handle_exception(exc_info, True)
  File "<template>", line 18, in top-level template code
  File "/usr/lib/python2.6/site-packages/salt/modules/cmdmod.py", line 1099, in retcode
    use_vt=use_vt)
  File "/usr/lib/python2.6/site-packages/salt/modules/cmdmod.py", line 387, in _run
    proc = salt.utils.timed_subprocess.TimedProc(cmd, **kwargs)
  File "/usr/lib/python2.6/site-packages/salt/utils/timed_subprocess.py", line 25, in __init__
    self.process = subprocess.Popen(args, **kwargs)
  File "/usr/lib64/python2.6/subprocess.py", line 642, in __init__
    errread, errwrite)
  File "/usr/lib64/python2.6/subprocess.py", line 1234, in _execute_child
    raise child_exception
TypeError: execve() argument 1 must be encoded string without NULL bytes, not str

; line 18

---
[...]
      - file: /tmp/dependent_file
    - watch:
      - file: managed_dependent_file

# If CDH parcels have been deployed create necessary symlinks
{% if 0 == salt['cmd.retcode']('test -h '~ TEST_SYMLINK ~' ') %}    <======================
{{ TEST_SYMLINK }}:
  file.symlink:
    - target: /opt/yp
    - force: True
{% endif %}
[...]

wongster80 avatar Jul 27 '15 21:07 wongster80

@wongster80, thanks for the report. Does the state work if you change this line:

{% if 0 == salt['cmd.retcode']('test -h '~ TEST_SYMLINK ~' ', python_shell=True) %}

jfindlay avatar Jul 28 '15 18:07 jfindlay

@jfindlay your suggestion to pass python_shell=True worked

Thanks

wongster80 avatar Jul 29 '15 23:07 wongster80

@wongster80, would you consider this issue to be resolved?

jfindlay avatar Jul 30 '15 04:07 jfindlay