在 Docker 中运行时,Fetch 模块返回“无法计算远程文件的校验和”,但不在 Docker 中时工作正常

2024-01-27

Ansible 手册(复制文件.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

当我运行它时它起作用了。

但是当我将其docker化时,它给了我error:

fatal: [remotehost.com]: FAILED! => {"changed": false, "file": "/tmp/file_to_copy", "msg": "unable to calculate the checksum of the remote file"}

我的 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


Q: *"fatal: ... {"file": "/tmp/file_to_copy", "msg": "无法计算远程文件的校验和"}

答: 尝试找出原因stat https://docs.ansible.com/ansible/latest/modules/stat_module.html#stat-retrieve-file-or-file-system-status回报checksum: 0。例如

- hosts: remotehost.com
  tasks:
    - stat:
        path: /tmp/file_to_copy
      register: result
    - debug:
        var: result.stat.checksum

Notes

  • See 无法计算远程文件的校验和。外壳是bash。 ansible 版本 2.0.2.0 #29769 https://github.com/ansible/ansible/issues/29769

  • 校验和为0时报错,参见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/插件/操作/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']
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在 Docker 中运行时,Fetch 模块返回“无法计算远程文件的校验和”,但不在 Docker 中时工作正常 的相关文章

随机推荐