我的盐栈仆从有个奇怪的问题。我在Ubuntu16.04上安装了仆从,到主服务器的连接也很好。但是,当我试图在我的仆从上创建一个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发布于 2017-05-31 16:18:12
在最近的盐分版本中,osmajorrelease谷物从字符串转换为整数(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 %}希望这能有所帮助!
https://stackoverflow.com/questions/44279484
复制相似问题