英文:
Fetch module returns "unable to calculate the checksum of the remote file" while running in Docker but works fine when not in Docker
问题
Ansible playbook (copy_file.yml):
- name: 请复制此文件
hosts: all
gather_facts: false
tasks:
- name: 从每个数据中心运行的扫描仪获取文件
fetch:
src: /tmp/file_to_copy
dest: /tmp/local_place
flat: yes
fail_on_missing: yes
validate_checksum: no
Command: ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook -i inventory playbook/copy_file.yml
它在我运行时有效。
但是当我将其制作成 Docker 容器时,它会给我错误:
致命错误: [remotehost.com]: 失败! => {"changed": false, "file": "/tmp/file_to_copy", "msg": "无法计算远程文件的校验和"}
我的 Dockerfile 非常简单。它只是复制一个包含 Ansible 命令的脚本并运行它。其基础镜像是 Alpine Linux
。
Dockerfile:
FROM some_url/alpine/python:3.7-alpine
RUN apk add --no-cache musl-dev libffi-dev openssl-dev
RUN apk add build-base
RUN apk add bash
COPY / /
RUN pip install -r requirements.txt
ENTRYPOINT ["/run.sh"]
Ansible 版本: ansible 2.9.2
英文:
Ansible playbook (copy_file.yml):
- name: Copy this file over please
hosts: all
gather_facts: false
tasks:
- name: Get files from scanners running in each DC
fetch:
src: /tmp/file_to_copy
dest: /tmp/local_place
flat: yes
fail_on_missing: yes
validate_checksum: no
Command: ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook -i inventory playbook/copy_file.yml
It works when I run it.
But when I dockerize it, it gives me the error:
fatal: [remotehost.com]: FAILED! => {"changed": false, "file": "/tmp/file_to_copy", "msg": "unable to calculate the checksum of the remote file"}
My dockerfile is very simple. It just copies a script that contains the ansible command and runs it. Its base image is Alpine Linux
.
Dockerfile:
FROM some_url/alpine/python:3.7-alpine
RUN apk add --no-cache musl-dev libffi-dev openssl-dev
RUN apk add build-base
RUN apk add bash
COPY / /
RUN pip install -r requirements.txt
ENTRYPOINT ["/run.sh"]
Ansible version: ansible 2.9.2
答案1
得分: 3
"A: 尝试找出为什么 stat 返回 checksum: 0
。例如
- hosts: remotehost.com
tasks:
- stat:
path: /tmp/file_to_copy
register: result
- debug:
var: result.stat.checksum
Notes
-
请参阅 Unable to calculate the checksum of the remote file. Shell is bash. ansible ver 2.0.2.0 #29769
-
当 checksum 为 0 时报告错误。请参阅 lib/ansible/plugins/action/fetch.py
if remote_checksum == '0':
result['msg'] = "无法计算远程文件的校验和"
def _remote_checksum(self, path, all_vars, follow=False):
...
x = "0" # 未知错误发生
try:
remote_stat = self._execute_remote_stat(path, all_vars, follow=follow)
...
x = remote_stat['checksum'] # 如果为 1,则文件丢失
...
return x # pylint: disable=lost-exception
def _execute_remote_stat(self, path, all_vars, follow, tmp=None, checksum=True):
...
mystat = self._execute_module(module_name='stat', module_args=module_args, task_vars=all_vars, wrap_async=False)
...
return mystat['stat']
```"
<details>
<summary>英文:</summary>
>Q: *"fatal: ... {"file": "/tmp/file_to_copy", "msg": "unable to calculate the checksum of the remote file"}
A: Try to find out why [stat](https://docs.ansible.com/ansible/latest/modules/stat_module.html#stat-retrieve-file-or-file-system-status) returns `checksum: 0`. For example
- hosts: remotehost.com
tasks:
- stat:
path: /tmp/file_to_copy
register: result
- debug:
var: result.stat.checksum
<hr>
Notes
* See [Unable to calculate the checksum of the remote file. Shell is bash. ansible ver 2.0.2.0 #29769](https://github.com/ansible/ansible/issues/29769)
* The error is reported when the checksum is 0. See [lib/ansible/plugins/action/fetch.py](https://github.com/ansible/ansible/blob/devel/lib/ansible/plugins/action/fetch.py)
if remote_checksum == '0':
result['msg'] = "unable to calculate the checksum of the remote file"
* See [lib/ansible/plugins/action/__init__.py](https://github.com/ansible/ansible/blob/devel/lib/ansible/plugins/action/__init__.py)
def _remote_checksum(self, path, all_vars, follow=False):
...
x = "0" # unknown error has occurred
try:
remote_stat = self._execute_remote_stat(path, all_vars, follow=follow)
...
x = remote_stat['checksum'] # if 1, file is missing
...
return x # pylint: disable=lost-exception
def _execute_remote_stat(self, path, all_vars, follow, tmp=None, checksum=True):
...
mystat = self._execute_module(module_name='stat', module_args=module_args, task_vars=a
ll_vars, wrap_async=False)
...
return mystat['stat']
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论