Linux控制器上的Ansible-s3模块,用于从windows主机复制到s3存储桶



我在AWS EC2linux机器上运行我的ansible,该机器连接到另一台AWS EC2Windows计算机以将文件复制到S3 bucket

我的任务/main.yml文件在下面看起来像

---
# tasks file for postgres

- name: Simple PUT operation
amazon.aws.aws_s3:
bucket: codepipeline-artefact-12344555-abc
object: /test.txt
src: "C:\teststore-selenium\test.txt"
mode: put

ansible.cfg文件如下

[defaults]
log_path = /var/log/ansible.log
ansible_python_interpreter = /usr/bin/python

并且主机文件在下面看起来像

[win]
10.x.x.5:5986
[win:vars]
ansible_user=Administrator
ansible_port=5986
ansible_password=****PasswordRemoved****
ansible_connection=winrm
ansible_winrm_server_cert_validation=ignore
ansible_winrm_transport=basic
ansible_python_interpreter="c:usersadministratorappdatalocalprogramspythonpython310"
#ansible_winrm_read_timeout_sec=60
#ansible_winrm_operation_timeout_sec=60
ansible_shell_type=powershell
ansible_shell_executable=None

我在运行剧本时出错了。以下错误

[WARNING]: log file at /var/log/ansible.log is not writeable and we cannot create it, aborting
[DEPRECATION WARNING]: Ansible will require Python 3.8 or newer on the controller starting with Ansible 2.12. Current version: 3.6.8 (default, Aug
12 2021, 07:06:15) [GCC 8.4.1 20200928 (Red Hat 8.4.1-1)]. This feature will be removed from ansible-core in version 2.12. Deprecation warnings
can be disabled by setting deprecation_warnings=False in ansible.cfg.
ansible-playbook [core 2.11.7]
config file = /etc/ansible/ansible.cfg
configured module search path = ['/home/ec2-user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python3.6/site-packages/ansible
ansible collection location = /home/ec2-user/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/local/bin/ansible-playbook
python version = 3.6.8 (default, Aug 12 2021, 07:06:15) [GCC 8.4.1 20200928 (Red Hat 8.4.1-1)]
jinja version = 2.10.1
libyaml = True
Using /etc/ansible/ansible.cfg as config file
host_list declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
auto declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Parsed /etc/ansible/hosts inventory source with ini plugin
redirecting (type: action) ansible.builtin.win_copy to ansible.windows.win_copy
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: role_postgres.yml ***********************************************************************************************************************
1 plays in role_postgres.yml
PLAY [all] ****************************************************************************************************************************************
TASK [postgres : Simple PUT operation] ************************************************************************************************************
task path: /etc/ansible/roles/postgres/tasks/main.yml:10
<10.x.x.5> ESTABLISH WINRM CONNECTION FOR USER: Administrator on PORT 5986 TO 10.x.x.5
EXEC (via pipeline wrapper)
EXEC (via pipeline wrapper)
Using module file /usr/local/lib/python3.6/site-packages/ansible_collections/amazon/aws/plugins/modules/aws_s3.py
Pipelining is enabled.
EXEC (via pipeline wrapper)
EXEC (via pipeline wrapper)
The full traceback is:
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/ansible/plugins/action/__init__.py", line 1176, in _parse_returned_data
filtered_output, warnings = _filter_non_json_lines(res.get('stdout', u''), objects_only=True)
File "/usr/local/lib/python3.6/site-packages/ansible/module_utils/json_utils.py", line 57, in _filter_non_json_lines
raise ValueError('No start of json char found')
ValueError: No start of json char found
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/ansible/executor/task_executor.py", line 158, in run
res = self._execute()
File "/usr/local/lib/python3.6/site-packages/ansible/executor/task_executor.py", line 582, in _execute
result = self._handler.run(task_vars=variables)
File "/usr/local/lib/python3.6/site-packages/ansible_collections/amazon/aws/plugins/action/aws_s3.py", line 63, in run
result = merge_hash(result, self._execute_module(module_args=new_module_args, task_vars=task_vars, wrap_async=wrap_async))
File "/usr/local/lib/python3.6/site-packages/ansible/plugins/action/__init__.py", line 1116, in _execute_module
data = self._parse_returned_data(res)
File "/usr/local/lib/python3.6/site-packages/ansible/plugins/action/__init__.py", line 1200, in _parse_returned_data
match = re.compile('%s: (?:No such file or directory|not found)' % self._used_interpreter.lstrip('!#'))
File "/usr/lib64/python3.6/re.py", line 233, in compile
return _compile(pattern, flags)
File "/usr/lib64/python3.6/re.py", line 301, in _compile
p = sre_compile.compile(pattern, flags)
File "/usr/lib64/python3.6/sre_compile.py", line 562, in compile
p = sre_parse.parse(p, flags)
File "/usr/lib64/python3.6/sre_parse.py", line 855, in parse
p = _parse_sub(source, pattern, flags & SRE_FLAG_VERBOSE, 0)
File "/usr/lib64/python3.6/sre_parse.py", line 416, in _parse_sub
not nested and not items))
File "/usr/lib64/python3.6/sre_parse.py", line 502, in _parse
code = _escape(source, this, state)
File "/usr/lib64/python3.6/sre_parse.py", line 362, in _escape
raise source.error("incomplete escape %s" % escape, len(escape))
sre_constants.error: incomplete escape u at position 2
fatal: [10.209.31.5]: FAILED! => {
"msg": "Unexpected failure during module execution.",
"stdout": ""
}

如果你能帮忙的话,不确定出了什么问题。提前感谢

您收到了关于返回值json格式的投诉。当请求格式不正确时,通常会发生这种情况。我看到tasks/main.yml的src和object字段中都有"test.txt";检查这是否是多余的。

接下来,我将使用这些凭据对AWS直接查询该对象,并查看响应

最新更新