以前解决过一次,是定义LC_ALL为指定编码。但这种思路不完全,因为机器各各不同,系统编码本身不一致(标准化之路漫长啊)
故而在其它一些系统的部署时,用上一次的方案,反而会有错误产生。
于是,按洪军找到的另一种方案,这次理想多了。
URL如下:
http://blog.csdn.net/hnhuangyiyang/article/details/50421738
这个帖子操作的是命令行,如果作API的话,要变换一下。
# ok def cmd_run(self, tgt, arg, expr_form='compound', fun='cmd.run'): r = requests.post(self.host, verify=False, cookies=self.cookies, data={'tgt': tgt, 'client': 'local', 'expr_form': expr_form, 'fun': fun, 'arg': arg}) if r.status_code == 200: # print r.json() return r.json() else: raise Exception('Error from source %s' % r.text) # ok def cmd_script(self, tgt, arg, expr_form='compound', fun='cmd.script'): r = requests.post(self.host, verify=False, cookies=self.cookies, data={'tgt': tgt, 'client': 'local', 'expr_form': expr_form, 'fun': fun, 'arg': arg}) if r.status_code == 200: # print r.json() return r.json() else: raise Exception('Error from source %s' % r.text)
调用:
args = [salt_cmd.strip(), server_type+' '+site_name+' '+app+' '+deploy_version+' '+action+' '+is_inc_tot+' '+server_env, 'runas='+op_name, 'env={"LC_ALL": ""}']
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
命令行执行:
如:
salt '10.0.10.100' cmd.run 'locale' env='{"LC_ALL": ""}' #增加参数env='{"LC_ALL": ""}'
编写state.sls:
locale:
cmd.run:
- name: locale
- env:
- LC_ALL: ""
以上即可解决执行cmdmod.py修改字符集的问题。
值得庆幸的是,https://github.com/saltstack/salt上目前最新版的salt 2015.8.3已经将这个问题解决了,新的cmdmod.py源码修改了。