file.managed encoding option isn't working
FreeBSD php-fpm package installs some initial config file and one of which has a UTF-8 character in it. The www.conf file. My file.managed has encoding: utf_8 and encoding_errors: ignore and salt still throws an error about ascii decoding problems. Am I missing something?
SLS section:
php-www_conf:
file.managed:
- source:
- salt://files/server/services/php/{{ grains['owner'] }}.{{ grains['role'] }}.{{ grains['phpversion'] }}/www.conf
- user: root
- mode: 644
- encoding: utf_8
- encoding_errors: ignore
- require:
- pkg: php71
- require_in:
- service: php71_service
{% if grains['os'] == 'FreeBSD' %}
- name: /usr/local/etc/php-fpm.d/www.conf
- group: wheel
{% elif grains['os'] == 'Debian' %}
- name: /etc/php-fpm.conf
- group: root
{% endif %}
When I run a highstate against the minion I get:
ID: php-www_conf
Function: file.managed
Name: /usr/local/etc/php-fpm.d/www.conf
Result: False
Comment: An exception occurred in this state: Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/salt/state.py", line 1851, in call
**cdata['kwargs'])
File "/usr/local/lib/python3.6/site-packages/salt/loader.py", line 1795, in wrapper
return f(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/salt/states/file.py", line 2331, in managed
**kwargs
File "/usr/local/lib/python3.6/site-packages/salt/modules/file.py", line 4445, in check_managed_changes
group, mode, saltenv, contents)
File "/usr/local/lib/python3.6/site-packages/salt/modules/file.py", line 4535, in check_file_meta
nlines = name_.readlines()
File "/usr/local/lib/python3.6/encodings/ascii.py", line 26, in decode
return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 770: ordinal not in range(128)
Versions Report
master and minion are same version.
Salt Version:
Salt: 2017.7.4
Dependency Versions:
cffi: 1.11.3
cherrypy: Not Installed
dateutil: 2.6.1
docker-py: Not Installed
gitdb: Not Installed
gitpython: Not Installed
ioflo: Not Installed
Jinja2: 2.10
libgit2: Not Installed
libnacl: Not Installed
M2Crypto: Not Installed
Mako: Not Installed
msgpack-pure: Not Installed
msgpack-python: 0.4.7
mysql-python: 1.3.12
pycparser: 2.10
pycrypto: 2.6.1
pycryptodome: Not Installed
pygit2: Not Installed
Python: 3.6.4 (default, Dec 23 2017, 09:14:16)
python-gnupg: Not Installed
PyYAML: 3.12
PyZMQ: 16.0.3
RAET: Not Installed
smmap: Not Installed
timelib: Not Installed
Tornado: 4.5.3
ZMQ: 4.2.3
System Versions:
dist:
locale: UTF-8
machine: amd64
release: 11.1-RELEASE-p4
system: FreeBSD
version: Not Installed
@rhavenn Thanks for the report. In releases prior to the upcoming Oxygen (2018.3.0) release there were a lot of places within the code where ascii encoding was assumed which results in a lot of these types of errors. For Oxygen there was a huge effort to move things to use Unicode, so this issue should be resolved with that release.
@garethgreenaway I just upgraded to 2018.3.0 and it basically broke file.managed with binary files from contents_pillar. https://github.com/saltstack/salt/issues/46858#issuecomment-378658104 suggests disabling show_changes as a workaround but that combined with the encoding option not working breaks this.
I didn't have to use the encoding option in 2017.x
Do you know if there are any workarounds for this?
ID: /srv/server/session-ticket-keys/0.key
Function: file.managed
Result: False
Comment: An exception occurred in this state: Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/salt/state.py", line 1878, in call
**cdata['kwargs'])
File "/usr/lib/python2.7/dist-packages/salt/loader.py", line 1823, in wrapper
return f(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/salt/states/file.py", line 2267, in managed
isinstance(use_contents, six.string_types) and '\0' in use_contents
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc6 in position 0: ordinal not in range(128)
Started: 14:41:06.189828
This is also a big issue for me.
The error that I'm seeing:
An exception occurred in this state: Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/salt/state.py", line 1878, in call
**cdata['kwargs'])
File "/usr/lib/python3/dist-packages/salt/loader.py", line 1823, in wrapper
return f(*args, **kwargs)
File "/usr/lib/python3/dist-packages/salt/states/x509.py", line 712, in pem_managed
file_args['contents'] = __salt__['x509.get_pem_entry'](text=text).encode()
File "/usr/lib/python3/dist-packages/salt/loader.py", line 1823, in wrapper
return f(*args, **kwargs)
File "/usr/lib/python3/dist-packages/salt/states/file.py", line 2267, in managed
isinstance(use_contents, six.string_types) and '\0' in use_contents
TypeError: a bytes-like object is required, not 'str'
Versions Report:
Salt Version:
Salt: 2018.3.0
Dependency Versions:
cffi: 1.5.2
cherrypy: 3.5.0
dateutil: 2.7.3
docker-py: Not Installed
gitdb: 0.6.4
gitpython: 1.0.1
ioflo: 1.7.4
Jinja2: 2.10
libgit2: Not Installed
libnacl: 1.6.1
M2Crypto: 0.30.1
Mako: 1.0.7
msgpack-pure: Not Installed
msgpack-python: 0.5.6
mysql-python: Not Installed
pycparser: 2.18
pycrypto: 3.6.1
pycryptodome: Not Installed
pygit2: Not Installed
Python: 3.5.2 (default, Nov 23 2017, 16:37:01)
python-gnupg: 0.4.2
PyYAML: 3.12
PyZMQ: 17.0.0
RAET: 0.6.8
smmap: 0.9.0
timelib: 0.2.4
Tornado: 4.2.1
ZMQ: 4.1.6
System Versions:
dist: Ubuntu 16.04 xenial
locale: UTF-8
machine: x86_64
release: 4.4.0-127-generic
system: Linux
version: Ubuntu 16.04 xenial
Same here, trying to use the CA methodology described in state x509 (uses Salt mine):
2018-11-25 00:25:40,361 [salt.state :320 ][ERROR ][14208] An exception occurred in this state: Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/salt/state.py", line 1913, in call
**cdata['kwargs'])
File "/usr/lib/python3/dist-packages/salt/loader.py", line 1898, in wrapper
return f(*args, **kwargs)
File "/usr/lib/python3/dist-packages/salt/states/x509.py", line 719, in pem_managed
return __states__['file.managed'](**file_args)
File "/usr/lib/python3/dist-packages/salt/loader.py", line 1898, in wrapper
return f(*args, **kwargs)
File "/usr/lib/python3/dist-packages/salt/states/file.py", line 2421, in managed
elif isinstance(use_contents, six.string_types) and str('\0') in use_contents:
TypeError: a bytes-like object is required, not 'str'
Salt Version:
Salt: 2018.3.3
Dependency Versions:
cffi: Not Installed
cherrypy: Not Installed
dateutil: 2.6.1
docker-py: Not Installed
gitdb: Not Installed
gitpython: Not Installed
ioflo: Not Installed
Jinja2: 2.10
libgit2: Not Installed
libnacl: Not Installed
M2Crypto: 0.30.1
Mako: Not Installed
msgpack-pure: Not Installed
msgpack-python: 0.5.6
mysql-python: Not Installed
pycparser: Not Installed
pycrypto: 2.6.1
pycryptodome: Not Installed
pygit2: Not Installed
Python: 3.6.7 (default, Oct 22 2018, 11:32:17)
python-gnupg: 0.4.1
PyYAML: 3.12
PyZMQ: 16.0.2
RAET: Not Installed
smmap: Not Installed
timelib: Not Installed
Tornado: 4.5.3
ZMQ: 4.2.5
System Versions:
dist: Ubuntu 18.04 bionic
locale: UTF-8
machine: x86_64
release: 4.15.0-39-generic
system: Linux
version: Ubuntu 18.04 bionic
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.