Brian Luong
Brian Luong

Reputation: 588

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: 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

Upvotes: 2

Views: 7581

Answers (1)

Vladimir Botka
Vladimir Botka

Reputation: 68124

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

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']

Upvotes: 3

Related Questions