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

标签 docker ansible ansible-2.x

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"}

答:尝试找出原因 stat返回校验和:0。例如

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

注释

if remote_checksum == '0':
    result['msg'] = "unable to calculate the checksum of the remote file"
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 - 在 Docker 中运行时,Fetch 模块返回 "unable to calculate the checksum of the remote file",但不在 Docker 中时工作正常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59574516/

相关文章:

Azure Artifacts 在尝试构建 Dockerfile 时给出未经授权的信息

ansible - 在本地主机上运行一个 ansible playbook 任务,然后在远程服务器上运行另一个任务

ansible - ansible回调是如何配置的

python - 尽管安装了 Ansible,但找不到 boto3 和 botocore

docker - 在带有docker-compose和x.pack auth的Docker中使用Docker中的ELK Stack无法验证用户

docker - 暴露Docker容器端口不起作用

amazon-web-services - AWS SSM 作为 Terraform 中任务的 valueFrom 不起作用

ansible 动态主机拒绝使用自定义解释器

linux - Ansible amazon linux 权限被拒绝(公钥)

使用 group_by 时 Ansible 将看不到处理程序