I have a strange problem with my Saltstack minions. I installed the minions on Ubuntu 16.04 and the connection to the master works fine. But as soon I try to make on my minion a state.apply I get a Jinja template error:
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
I checked the grain items on the minion:
os:
Ubuntu
os_family:
Debian
osarch:
amd64
oscodename:
xenial
osfinger:
Ubuntu-16.04
osfullname:
Ubuntu
osmajorrelease:
16
osrelease:
16.04
osrelease_info:
- 16
- 4
The hosts are EC2 instances, on a other host with the same setup it works fine. Attached you find the salt --versions-report: Salt Version:
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
In recent Salt versions osmajorrelease
grain was converted from string to integer (https://github.com/saltstack/salt/issues/35972). The error you get is saying that your Jinja template expects string but gets integer instead ( TypeError: coercing to Unicode: need string or buffer, int found
).
I'm not sure what exactly is being done inside of the state but one way to solve this would be to convert integer into string inside of your .jinja
file. For example like this:
{% set osrelease = salt['grains.get']('osrelease')|string %}
Hope this helps!