gpt4 book ai didi

docker - Fetch 模块在 Docker 中运行时返回 "unable to calculate the checksum of the remote file",但在不在 Docker 中时工作正常

转载 作者:行者123 更新时间:2023-12-02 19:21:12 25 4
gpt4 key购买 nike

Ansible 手册 (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

命令 : ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook -i inventory playbook/copy_file.yml
当我运行它时它工作。

但是当我将它 dockerize 时,它​​给了我 错误 :
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": "unable to calculate the checksum of the remote file"}



A: 尝试找出原因 stat返回 checksum: 0 .例如
- hosts: remotehost.com
tasks:
- stat:
path: /tmp/file_to_copy
register: result
- debug:
var: result.stat.checksum

笔记
  • Unable to calculate the checksum of the remote file. Shell is bash. ansible ver 2.0.2.0 #29769
  • 校验和为0时报错。见lib/ansible/plugins/action/fetch.py
  • if remote_checksum == '0':
    result['msg'] = "unable to calculate the checksum of the remote file"
  • 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']

    关于docker - Fetch 模块在 Docker 中运行时返回 "unable to calculate the checksum of the remote file",但在不在 Docker 中时工作正常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59574516/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com