gpt4 book ai didi

python - SaltStack 颗粒错误

转载 作者:行者123 更新时间:2023-12-04 18:55:59 24 4
gpt4 key购买 nike

我的 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

我检查了小兵身上的 Cereal 元素:
  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 --versions-report:
salt 版:
         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

最佳答案

在最近的 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 %}

希望这可以帮助!

关于python - SaltStack 颗粒错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44279484/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com