docker - Fetch 模块在 Docker 中运行时返回“无法计算远程文件的校验和”,但在不在 Docker 中时工作正常
问题描述
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": "无法计算远程文件的校验和"}
A:尝试找出stat返回的原因checksum: 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']
推荐阅读
- python - Docker 中的 MLFlow - 无法在 sftp 服务器 (atmoz) 中存储工件
- python - Ansible“ansible_python_interpreter”错误
- typescript - TypeScript 自定义对象映射
- django - 在 Django Rest Framework 中更新具有唯一字段的模型
- intellij-idea - 如何将文本颜色更改为具有深色背景的 intellij 工具窗口文本区域的灯光?
- android - 使用 Google Maps API v2 时,签名的 APK 崩溃,未签名的 APK
- netsuite - 如何克服 Suitescript 1.0 中的内存占用问题
- c++ - C++ 程序显示我使用字符串函数清除的数组索引的名称?
- java - 询问如何从地图上的地图中获取价值,就像这段代码一样
- python - 您可以通过 tkinter-Python 运行 .exe 文件吗?