问题
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:
Q: *"fatal: ... {"file": "/tmp/file_to_copy", "msg": "unable to calculate the checksum of the remote file"}
A: Try to find out why stat returns checksum: 0
. For example
- hosts: remotehost.com
tasks:
- stat:
path: /tmp/file_to_copy
register: result
- debug:
var: result.stat.checksum
Notes
See Unable to calculate the checksum of the remote file. Shell is bash. ansible ver 2.0.2.0 #29769
The error is reported when the checksum is 0. See 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
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']
来源:https://stackoverflow.com/questions/59574516/fetch-module-returns-unable-to-calculate-the-checksum-of-the-remote-file-while