Fetch module returns "unable to calculate the checksum of the remote file" while running in Docker but works fine when not in Docker

huangapple go评论110阅读模式
英文:

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

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>

&gt;Q: *&quot;fatal: ... {&quot;file&quot;: &quot;/tmp/file_to_copy&quot;, &quot;msg&quot;: &quot;unable to calculate the checksum of the remote file&quot;}

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

&lt;hr&gt;

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>



huangapple
  • 本文由 发表于 2020年1月3日 15:09:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/59574516.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定