mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Avoid breaking on unicode input when logging to syslog in modules
After commit 254f87e
, non-ascii input broke logging to syslog.
This commit is contained in:
parent
daa3253b52
commit
7e23ed345f
3 changed files with 35 additions and 2 deletions
|
@ -814,10 +814,10 @@ class AnsibleModule(object):
|
||||||
except IOError, e:
|
except IOError, e:
|
||||||
# fall back to syslog since logging to journal failed
|
# fall back to syslog since logging to journal failed
|
||||||
syslog.openlog(str(module), 0, syslog.LOG_USER)
|
syslog.openlog(str(module), 0, syslog.LOG_USER)
|
||||||
syslog.syslog(syslog.LOG_NOTICE, msg.encode('utf8'))
|
syslog.syslog(syslog.LOG_NOTICE, msg.decode('utf8').encode('utf8'))
|
||||||
else:
|
else:
|
||||||
syslog.openlog(str(module), 0, syslog.LOG_USER)
|
syslog.openlog(str(module), 0, syslog.LOG_USER)
|
||||||
syslog.syslog(syslog.LOG_NOTICE, msg.encode('utf8'))
|
syslog.syslog(syslog.LOG_NOTICE, msg.decode('utf8').encode('utf8'))
|
||||||
|
|
||||||
def get_bin_path(self, arg, required=False, opt_dirs=[]):
|
def get_bin_path(self, arg, required=False, opt_dirs=[]):
|
||||||
'''
|
'''
|
||||||
|
|
|
@ -409,6 +409,22 @@ class TestPlaybook(unittest.TestCase):
|
||||||
|
|
||||||
assert utils.jsonify(expected, format=True) == utils.jsonify(actual,format=True)
|
assert utils.jsonify(expected, format=True) == utils.jsonify(actual,format=True)
|
||||||
|
|
||||||
|
def test_playbook_logging_non_ascii(self):
|
||||||
|
pb = 'test/playbook-logging-non-ascii.yml'
|
||||||
|
actual = self._run(pb)
|
||||||
|
|
||||||
|
expected = {
|
||||||
|
"localhost": {
|
||||||
|
"changed": 3,
|
||||||
|
"failures": 0,
|
||||||
|
"ok": 3,
|
||||||
|
"skipped": 0,
|
||||||
|
"unreachable": 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
assert utils.jsonify(expected, format=True) == utils.jsonify(actual, format=True)
|
||||||
|
|
||||||
|
|
||||||
# Disabled for now as there are permissions issues that happen if you are not the owner that created files
|
# Disabled for now as there are permissions issues that happen if you are not the owner that created files
|
||||||
# in the archive.
|
# in the archive.
|
||||||
|
|
17
test/playbook-logging-non-ascii.yml
Normal file
17
test/playbook-logging-non-ascii.yml
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
---
|
||||||
|
- hosts: localhost
|
||||||
|
connection: local
|
||||||
|
gather_facts: False
|
||||||
|
|
||||||
|
tasks:
|
||||||
|
- name: Loggføring fungerer
|
||||||
|
command: echo "Feilsøking"
|
||||||
|
always_run: yes
|
||||||
|
|
||||||
|
- name: Die Süßigkeit
|
||||||
|
command: echo "Die Süßigkeit"
|
||||||
|
always_run: yes
|
||||||
|
|
||||||
|
- name: Logging works
|
||||||
|
command: echo "Debugging"
|
||||||
|
always_run: yes
|
Loading…
Reference in a new issue