Ansible gcp_storage_object_module: UnicodeDecodeError: 'utf-8' codec can't decode byte 0x87 in posit

Posted

技术标签:

【中文标题】Ansible gcp_storage_object_module: UnicodeDecodeError: \'utf-8\' codec can\'t decode byte 0x87 in position【英文标题】:Ansible gcp_storage_object_module: UnicodeDecodeError: 'utf-8' codec can't decode byte 0x87 in positionAnsible gcp_storage_object_module: UnicodeDecodeError: 'utf-8' codec can't decode byte 0x87 in position 【发布时间】:2022-01-13 10:43:20 【问题描述】:

云位置需要进行 URL 编码,包括斜杠。 如何对位置进行 URL 编码并保存在 ansible 中。

Ansible 任务:

  - name: Push artifacts to GCS
    google.cloud.gcp_storage_object:
      action: upload
      bucket: " bucket "
      src: "/tmp/jars/CounterWebApp.war"
      dest: "~/CounterWebApp.war"
      project: " project "
      auth_kind: serviceaccount
      service_account_file: "sa.json"

错误:

"module_stdout": "Traceback (most recent call last):\r\n  File \"/root/.ansible/tmp/ansible-tmp-1638969252.5433185-299097-261667259852506/AnsiballZ_gcp_storage_object.py\", line 102, in <module>\r\n    _ansiballz_main()\r\n  File \"/root/.ansible/tmp/ansible-tmp-1638969252.5433185-299097-261667259852506/AnsiballZ_gcp_storage_object.py\", line 94, in _ansiballz_main\r\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\r\n  File \"/root/.ansible/tmp/ansible-tmp-1638969252.5433185-299097-261667259852506/AnsiballZ_gcp_storage_object.py\", line 40, in invoke_module\r\n    runpy.run_module(mod_name='ansible_collections.google.cloud.plugins.modules.gcp_storage_object', init_globals=None, run_name='__main__', alter_sys=True)\r\n  File \"/usr/lib64/python3.6/runpy.py\", line 205, in run_module\r\n    return _run_module_code(code, init_globals, run_name, mod_spec)\r\n  File \"/usr/lib64/python3.6/runpy.py\", line 96, in _run_module_code\r\n    mod_name, mod_spec, pkg_name, script_name)\r\n  File \"/usr/lib64/python3.6/runpy.py\", line 85, in _run_code\r\n    exec(code, run_globals)\r\n  File \"/tmp/ansible_google.cloud.gcp_storage_object_payload_m676xefz/ansible_google.cloud.gcp_storage_object_payload.zip/ansible_collections/google/cloud/plugins/modules/gcp_storage_object.py\", line 301, in <module>\r\n  File \"/tmp/ansible_google.cloud.gcp_storage_object_payload_m676xefz/ansible_google.cloud.gcp_storage_object_payload.zip/ansible_collections/google/cloud/plugins/modules/gcp_storage_object.py\", line 232, in main\r\n  File \"/tmp/ansible_google.cloud.gcp_storage_object_payload_m676xefz/ansible_google.cloud.gcp_storage_object_payload.zip/ansible_collections/google/cloud/plugins/modules/gcp_storage_object.py\", line 255, in upload_file\r\n  File \"/usr/local/lib/python3.6/site-packages/google/cloud/storage/blob.py\", line 2594, in upload_from_file\r\n    retry=retry,\r\n  File \"/usr/local/lib/python3.6/site-packages/google/cloud/storage/blob.py\", line 2412, in _do_upload\r\n    retry=retry,\r\n  File \"/usr/local/lib/python3.6/site-packages/google/cloud/storage/blob.py\", line 2242, in _do_resumable_upload\r\n    response = upload.transmit_next_chunk(transport, timeout=timeout)\r\n  File \"/usr/local/lib/python3.6/site-packages/google/resumable_media/requests/upload.py\", line 503, in transmit_next_chunk\r\n    method, url, payload, headers = self._prepare_request()\r\n  File \"/usr/local/lib/python3.6/site-packages/google/resumable_media/_upload.py\", line 605, in _prepare_request\r\n    self._stream, self._chunk_size, self._total_bytes\r\n  File \"/usr/local/lib/python3.6/site-packages/google/resumable_media/_upload.py\", line 963, in get_next_chunk\r\n    payload = stream.read(chunk_size)\r\n  File \"/usr/lib64/python3.6/codecs.py\", line 321, in decode\r\n    (result, consumed) = self._buffer_decode(data, self.errors, final)\r\nUnicodeDecodeError: 'utf-8' codec can't decode byte 0x87 in position 12: invalid start byte\r\n",
"msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
"rc": 1

【问题讨论】:

【参考方案1】:

它似乎是一个known issue,有一个merged fix,但没有进入any recent release。 comments claim 必须将该集合的“主”版本添加到您的 requirements.yml 才能获得未发布的一个字符更改:-(

【讨论】:

以上是关于Ansible gcp_storage_object_module: UnicodeDecodeError: 'utf-8' codec can't decode byte 0x87 in posit的主要内容,如果未能解决你的问题,请参考以下文章

ansible使用

Ansible之ansible.cfg

ansible源码解读

ansible总结

Linux系统之Ansible的基本介绍

Ansible之路——第五章:Ansible的几个命令