Saltstack: Passing objects to templates

Quick one. When you pass a variable like this to a template through the context/default parameter it is iterpreted as a literal string:

server_xml:
  file:
    - managed
    - name: /opt/tomcat/conf/server.xml
    - template: jinja
    - source: salt://tomcat/files/server.xml.tmpl
    - context:
        deploy_conf: deploy_conf

Which means that you end up with errors like this:
Unable to manage file: Jinja variable 'unicode object' has no attribute 'control_port

To pass the object itself in you need to put it in the braces:

server_xml:
  file:
    - managed
    - name: /opt/tomcat/conf/server.xml
    - template: jinja
    - source: salt://tomcat/files/server.xml.tmpl
    - context:
        deploy_conf: {{ deploy_conf }}
This entry was posted in saltstack, technology. Bookmark the permalink.

Leave a Reply