My map.jinja is not working in new salt version 2017.7.2

91 views
Skip to first unread message

pankaj ghadge

unread,
Nov 7, 2017, 2:33:44 AM11/7/17
to Salt-users
Hello,

I need help related to map.jinja, it is not working in new salt version 2017.7.2 (Nitrogen), it was working fine with previous version 

I'm getting below error, What is wrong in My Map.jinja ?

local:
    Data failed to compile:
----------
    Rendering SLS 'ppd:base.tomcat' failed: Jinja variable 'dict object' has no attribute 'service_watch_file'



map.jinja
#jinja file for testing

{% set lookup_table = {
      "CentOS": {
        "6": {
          "service_watch_file": "/etc/init.d/tomcat",
          "init_file_src": "salt://base/tomcat/files/init"
          },
        "7": {
          "service_watch_file": "/etc/systemd/system/tomcat.service",
          "init_file_src": "salt://base/tomcat/files/tomcat.service"
        }
      }
} %}

{% set os_map = lookup_table.get(grains.os, {}) %}
{% set os_rel_map = os_map.get(grains.osmajorrelease, {}) %}


init.sls
{% from "base/tomcat/map.jinja" import os_rel_map with context %}

{% set tomcat_version = salt['pillar.get']('tomcat:version', '7.0.54') %}
{% set tomcat_base_version = salt['pillar.get']('tomcat:base_version', '7') %}
{% set install_path = salt['pillar.get']('tomcat:install_path', '/usr/local/tomcat') %}

# Download Tomcat and manage the service
tomcat:
  file.managed:
    - name: {{ install_path }}/apache-tomcat-{{tomcat_version}}.tar.gz
    - source: http://archive.apache.org/dist/tomcat/tomcat-{{ tomcat_base_version }}/v{{ tomcat_version }}/bin/apache-tomcat-{{ tomcat_version }}.tar.gz
    - source_hash: http://archive.apache.org/dist/tomcat/tomcat-{{ tomcat_base_version }}/v{{ tomcat_version }}/bin/apache-tomcat-{{ tomcat_version }}.tar.gz.md5
    - makedirs: True
  service:
    - enable: True
    - running
    - require:
      - file: {{ os_rel_map.service_watch_file }}
    - watch:
      - file: {{ install_path }}/apache-tomcat-{{tomcat_version}}/conf/tomcat-users.xml
      - file: {{ os_rel_map.service_watch_file }}



--- Thanks 

pankaj ghadge

unread,
Nov 7, 2017, 7:14:19 AM11/7/17
to Salt-users

In salt 2017 osmajorrelease treated as int not string, So I removed the quotes  

it works well in 2017, but what about previous version? 

pankaj ghadge

unread,
Nov 7, 2017, 9:26:25 AM11/7/17
to Salt-users
I don't know how {% set osrelease = salt['grains.get']('osmajorrelease') | int %} this worked for 2016 salt version, I wanted to convert it into string, but "string" didn't work so i used "int" just to check and it worked. it's weird       

map.jinja

#jinja file for testing

{% set lookup_table = {
      "CentOS": {
        6: {
          "service_watch_file": "/etc/init.d/tomcat",
          "init_file_src": "salt://base/tomcat/files/init"
          },
        7: {
          "service_watch_file": "/etc/systemd/system/tomcat.service",
          "init_file_src": "salt://base/tomcat/files/tomcat.service"
        }
      }
} %}

{% set os_map = lookup_table.get(grains.os, {}) %}

{% if grains.get('saltversion').startswith('2016') or grains.get('saltversion').startswith('2015') %}
{% set osrelease = salt['grains.get']('osmajorrelease') | int %}
{% else %}
{% set osrelease = salt['grains.get']('osmajorrelease') %}
{% endif %}

{% set os_rel_map = os_map.get(osrelease, {}) %}

BKeep

unread,
Feb 4, 2018, 11:14:43 AM2/4/18
to Salt-users
Thanks this post helped me.
Reply all
Reply to author
Forward
0 new messages