我在 AWS EC2 linux 机器上运行 ansible,该机器连接到另一台 AWS EC2 Windows 机器以将文件复制到 S3 存储桶
我的tasks/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
和hosts文件如下所示
[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:\users\administrator\appdata\local\programs\python\python310"
#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 对该对象进行直接查询,并查看响应是什么。
您应该将所有者文件更改为运行ansible的当前用户:
sudo chmod $USER:$USER /var/log/ansible.log
或者您可以删除
ansible.log
文件并使用正确的权限重新创建:
sudo rm /var/log/ansible.log
sudo touch /var/log/ansible.log