SaltStack谷物错误

时间:2017-05-31 08:26:48

标签: python ubuntu salt-stack

我的Saltstack奴才有一个奇怪的问题。 我在Ubuntu 16.04上安装了minions,并且与master的连接工作正常。 但是,一旦我尝试在我的小兵上做一个state.apply我得到一个Jinja模板错误:

jenkins01-prod:
      Data failed to compile:
----------
Rendering SLS 'base:salt.minion' failed: Jinja error: coercing to Unicode: need string or buffer, int found
 /var/cache/salt/minion/files/base/salt/map.jinja(43):
 ---
   [...]
 {##
 Setup variable using grains['os_family'] based logic, only add 
key:values here
that differ from whats in defaults.yaml
 ##}
  {% set osrelease = salt['grains.get']('osrelease') %}
 {% set os_family_map = salt['grains.filter_by']({    <======================
'Debian':  {
  'pkgrepo': 'deb http://repo.saltstack.com/apt/' +
  salt['grains.get']('os')|lower + '/' + salt['grains.get']('osmajorrelease', osrelease) + '/amd64/latest ' + salt['grains.get']('oscodename') + ' main',
  'key_url': 'https://repo.saltstack.com/apt/' + salt['grains.get']('os')|lower + '/' + salt['grains.get']('osmajorrelease', osrelease) + '/amd64/latest/SALTSTACK-GPG-KEY.pub',
  'libgit2': 'libgit2-22',
 [...]
---
Traceback (most recent call last):

self._body_stream = list(template.root_render_func(context))
 File "/var/cache/salt/minion/files/base/salt/map.jinja", line 43, in top-level template code
{% set os_family_map = salt['grains.filter_by']({
TypeError: coercing to Unicode: need string or buffer, int found

我检查了小兵的粮食物品:

  os:
       Ubuntu
   os_family:
       Debian
   osarch:
       amd64
   oscodename:
       xenial
   osfinger:
       Ubuntu-16.04
   osfullname:
       Ubuntu
   osmajorrelease:
       16
   osrelease:
       16.04
   osrelease_info:
       - 16
       - 4

主机是EC2实例,在具有相同设置的其他主机上,它可以正常工作。 附上你找到盐 - 逆转报告: 盐版本:

         Salt: 2017.5.0-191-gb43b89c

 Dependency Versions:
       cffi: Not Installed
   cherrypy: Not Installed
   dateutil: 2.4.2
  docker-py: Not Installed
      gitdb: Not Installed
  gitpython: Not Installed
      ioflo: Not Installed
     Jinja2: 2.8
    libgit2: Not Installed
    libnacl: Not Installed
   M2Crypto: Not Installed
       Mako: 1.0.3
  msgpack-pure: Not Installed
msgpack-python: 0.4.6
mysql-python: Not Installed
  pycparser: Not Installed
   pycrypto: 2.6.1
pycryptodome: Not Installed
     pygit2: Not Installed
     Python: 2.7.12 (default, Nov 19 2016, 06:48:10)
python-gnupg: Not Installed
     PyYAML: 3.11
      PyZMQ: 15.2.0
       RAET: Not Installed
      smmap: Not Installed
    timelib: Not Installed
    Tornado: 4.2.1
        ZMQ: 4.1.4

  System Versions:
       dist: Ubuntu 16.04 xenial
    machine: x86_64
    release: 4.4.0-78-generic
     system: Linux
    version: Ubuntu 16.04 xenial

1 个答案:

答案 0 :(得分:4)

在最近的Salt版本osmajorrelease中,grain从字符串转换为整数(https://github.com/saltstack/salt/issues/35972)。你得到的错误是你的Jinja模板需要字符串但是会得到整数(TypeError: coercing to Unicode: need string or buffer, int found)。

我不确定在状态中究竟是做了什么,但解决这个问题的一种方法是将整数转换为.jinja文件内的字符串。例如:

{% set osrelease = salt['grains.get']('osrelease')|string %}

希望这有帮助!